I define two tables: category and product. Product can belong in multiple 
categories; M:M relationship expressed thus:

db.define_table('category', Field('name'))
db.define_table('product', Field('name'), Field('categories', 'list:reference 
category'))

When I define the controller for adding a product to the database:

def new():
    form = SQLFORM(db.product)
    return dict(form=form)

It works fine. I get my Multiple Selection widget on the Product form. I 
can select multiple categories, as expected.

But if I switch the order of the two define_tables statements, such that 
the product table is defined prior to the category table, I don't get the 
widget I expected -- just an empty input field. Is this expected behavior, 
or am I missing something? Is it better practice to rearrange my table 
definitions, or perhaps to explicit any widgets/requires after all table 
definitions? (I couldn't find a reference to this in chapter 6 of the book.)

In my simplistic example, it's no big deal, but in other cases it would be 
less appealing to rearrange the table definitions. For example, if I wanted 
to base an M:M relationship off the auth_user table, I'd have to place the 
auth.define_tables after my define_tables.

best regards -Ricardo

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to