Hi, Just tried this and does the trick! :) I''m just a little unclear
on how these two (or more?) tables are linked once submitted?

Example: request forms.
There can be many types of requests and let's say that they all have a
set fields that all request forms have (like: name, email, priority,
created_on, etc...), then maybe the specifics can be unique to the
request (I.e. a new_build_request vs buildSystem_feature_request) -

In this case, I would combine the common 'rm_request' table & the
'new_build_request' table, then similarly, 'rm_request' table & the
'buildSystem_feature_request'

So when the form gets submitted, how does the select() work? How do we
correlate the data from rm_request to the new_build_request data?


And ditto on Carlos' question about updates :) How would that work?

Thanks,
Mart :)



On Dec 12 2010, 4:33 pm, Carlos <[email protected]> wrote:
> Hi,
>
> I am wondering how this solution (singleformwithlinkedtables) can
> be used for updates (in addition to creates)?.
>
> Thanks,
>
>    Carlos
>
> On Dec 6, 4:32 am, DenesL <[email protected]> wrote:
>
>
>
>
>
>
>
> > True, only restriction is no common field names.
> > I have added this to the book.
>
> > On Dec 5, 11:05 pm, mdipierro <[email protected]> wrote:
>
> > > No field names in comment yes. References between them is not a
> > > problem as long the reference fields are not writable and readable
> > > when generating theform.
>
> > > On Dec 5, 9:41 pm, DenesL <[email protected]> wrote:
>
> > > > This only works fortablesthat do not have field names in common
> > > > and have no references between them.
>
> > > > On Oct 16, 9:57 am, mdipierro <[email protected]> wrote:
>
> > > > > It often happens that you have twotables(for example 'client' and
> > > > > 'address' which arelinkedtogether by a reference and you want to
> > > > > create asingleformthat allows to insert info about one client and
> > > > > its default address. Here is how:
>
> > > > > model:
>
> > > > > db.define_table('client',
> > > > >      Field('name'))
> > > > > db.define_table('address',
> > > > >     Field('client',db.client,writable=False,readable=False),
> > > > >     Field('street'),Field('city'))
>
> > > > > controller:
>
> > > > > def register():
> > > > >    form=SQLFORM.factory(db.client,db.address)
> > > > >     ifform.accepts(request.vars):
> > > > >         id = db.client.insert(**db.client._filter_fields(form.vars))
> > > > >        form.vars.client=id
> > > > >         id = db.address.insert(**db.address._filter_fields(form.vars))
> > > > >         response.flash='Thanks for filling theform'
> > > > >     return dict(form=form)
>
> > > > > Notice the SQLFORM.factory (it makes ONEformusing public fields from
> > > > > bothtablesand inherits their validators too).
> > > > > Onformaccepts this does two inserts (some data in one table and some
> > > > > data in the other).
>
> > > > > Massimo

Reply via email to