Update: This feature is actually documented in 
http://web2py.com/book/default/chapter/07#One-form-for-multiple-tables, 
what a shame I didn't see it earlier...

Regards


On Sunday, May 13, 2012 9:30:41 PM UTC-3, csantos wrote:
>
> Hi,
> Suppose I have two tables, with a one-to-one relationship:
>
> db.define_table('user', Field('name'));
> db.define_table('car', Field('color'), Field('user_id', db.user))
>
> What is the easiest way to create an SQLFORM that would store 
> *correlated*data in both fields? For instance, create a user with name Steve 
> who owns a 
> red car, that would create two registries (name=Steve), (color=red, 
> user_id=<Steve's id>). As far as I'm concerned, I could do something like 
> this:
>
> form=SQLFORM.factory(db.user, db.car)
> if form.process().accepted:
>     # for what I've tested, only the user was inserted, so I have to 
> insert the car manually
>     if db.car.insert(color=request.vars.color, user_id=form.vars.id):
>         response.flash(T('Eh nois que voa'))
>
> But I'm not sure this is the best approach (in terms of security, 
> performance and software engineering). Any insights?
> Thanks
>

Reply via email to