Not that it was the best approach, but when I am hurried and have to
collect data for special db designs, I just customize the input with
SQLFORM.factory and, on form validation, explore the form and do CRUD
accordingly. You could use the multiple widget for the foods field.
form = SLQFORM.factory(Field("person", ...), Field("foods", ...))
# pre-populate the form with current data
...
if form.process(...)...
...
On 17 mar, 20:50, asklucas <[email protected]> wrote:
> Hello!
>
> I can't work out how to handle many to many relations in web2py!
>
> Assuming the following model:
>
> db.define_table( 'person',
>
> > Field( 'name', type = 'string'),
> > )
>
> > db.define_table( 'food',
> > Field( 'name', type = 'string'),
> > )
>
> > db.define_table( 'person_food',
> > Field( 'id_person', type = 'reference person'),
> > Field( 'id_food', type = 'reference food'),
> > )
>
> How can I create a view for adding a person which displays available foods
> with checkboxes and updates the person_food-table accordingly?
>
> Since I'm connecting to legacy databases I can't use the "tags"-like
> approach for many to many relations.
>
> Thank you very much!
>
> L.