On Wednesday, December 7, 2011 6:08:24 PM UTC-5, Vincenzo Ampolo wrote:
>
>  Hi all
>
> I'm new to web2py. I set up a many to many relationship like these ones:
>
> db.define_table('users_dictionaries',
>
>                 Field('user_id', db.auth_user, requires = 
> IS_IN_DB(db,'auth_user.id', db.auth_user._format)),
>
>                 Field('dictionary_id', db.dictionary, 
> requires=IS_IN_DB(db,'dictionary.id',db.dictionary._format,multiple=True)),
>
>                 )
>
> db.define_table('users_categories',
>
>                 Field('user_id', db.auth_user, requires = 
> IS_IN_DB(db,'auth_user.id', db.auth_user._format)),
>
>                 Field('category_id', db.category, 
> requires=IS_IN_DB(db,'category.id',db.category._format,multiple=True))
>
>                 )
>
>
You only use multiple=True if the field is of type list:reference, which 
enables it to store multiple reference values in a single field (I'm not 
sure that's what you want, though). If you want a true many-to-many 
relationship with a separate record in the link table for each 
user/dictionary and user/category combo, then do not set multiple=True (in 
that case, though, you'll only be able to select one dictionary or category 
at a time).

Anthony

 

Reply via email to