can the query in IS_IN_DB have more than one table?

884 views
Skip to first unread message

Ashraf Mansour

unread,
Feb 21, 2012, 1:57:35 PM2/21/12
to web2py-users
Hi All,

can the query in IS_IN_DB have more than one table?

And how the fields of these tables be referenced in the format, to be
shown in the dropbox ?

Thanks in advance.

Ashraf

Richard Vézina

unread,
Feb 21, 2012, 2:39:26 PM2/21/12
to web...@googlegroups.com
For represent I usually do :

lambda id: db.fktable1(id).represent_field # 1 table
lambda id: db.fktable2(db.fktable1(id).id).represent_field_table2 # 2 table

You can maybe proceding the same way, but I am not sure... I am still using old requires syntax...

Please report your experiment and how you solve it.

Richard

Ashraf Mansour

unread,
Feb 21, 2012, 4:21:56 PM2/21/12
to web2py-users
Thank you for the immediate reply.

please rewrite the example using the old requires syntax.

On Feb 21, 10:39 pm, Richard Vézina <ml.richard.vez...@gmail.com>
wrote:

Richard Vézina

unread,
Feb 21, 2012, 4:27:32 PM2/21/12
to web...@googlegroups.com
Old

IS_IN_DB(helper_set,'table.id','%(field1)s (%(field2)s)',multiple=True)

Maybe this work but not sure :

IS_IN_DB(helper_set,'table.id',db.table2(db.table1.id).fieldTable2,multiple=True)


Richard

Richard Vézina

unread,
Feb 21, 2012, 4:27:56 PM2/21/12
to web...@googlegroups.com
On Tue, Feb 21, 2012 at 4:27 PM, Richard Vézina <ml.richa...@gmail.com> wrote:
Old

IS_IN_DB(helper_set,'table.id','%(field1)s (%(field2)s)',multiple=True) # One table

Maybe this work but not sure :

IS_IN_DB(helper_set,'table.id',db.table2(db.table1.id).fieldTable2,multiple=True) # 2 tables

Ashraf Mansour

unread,
Feb 21, 2012, 4:33:06 PM2/21/12
to web2py-users
I will try both and i will let you know.

On Feb 22, 12:27 am, Richard Vézina <ml.richard.vez...@gmail.com>
wrote:
> On Tue, Feb 21, 2012 at 4:27 PM, Richard Vézina <ml.richard.vez...@gmail.com

Ashraf Mansour

unread,
Feb 21, 2012, 5:00:09 PM2/21/12
to web2py-users
Unfortunately, did not work (both).

Do you know of any running example?
in other words, where is it explained, old style and new style?

Richard Vézina

unread,
Feb 21, 2012, 5:22:14 PM2/21/12
to web...@googlegroups.com
Ok by new style I mean this syntax :

db.dog.owner.requires = IS_IN_DB(db,db.person.id,'%(name)s')

Instead of :

db.dog.owner.requires = IS_IN_DB(db, 'person.id', '%(name)s')


In red...

So, I assume this is possible I am maybe wrong :

db.dog.owner.requires = IS_IN_DB(db,db.person.id, db.person(db.person.id).name)

Then if that is possible, why not :

db.dog.owner.requires = IS_IN_DB(db,db.person.id,'%s' % db.person(db.person.id).name db.othertable(db.person(db.person.id).fk_to_other_table_id).field_other_table)

The way your table are related affect how you have to write the request...

db.table(id).field is nothing else then db(db.table.id == id).select(db.table.field).first().field

Richard

Richard Vézina

unread,
Feb 21, 2012, 5:26:40 PM2/21/12
to web...@googlegroups.com
Maybe reading IS_IN_DB doc could helps...

Richard

Ashraf Mansour

unread,
Feb 22, 2012, 1:31:16 AM2/22/12
to web2py-users
Thank you for your support.

It has been solved by rewriting the arguments of IS_IN_DB.
The format (3rd argument) should not contain dot and should come from
only one table, which is the table of the second argument.
The query (1st argument) can reference more than one table (one of
them is used in the second and third argument, and it is the one that
contain the description that is required to be shown in the dropbox).
my mistake was that I thought that the second argument can be any one
of the two that are equated in the query, but choosing one will choose
that table that will be used in the format (third argument).

Thanks again and see you in the next opportunity.

Ashraf




On Feb 22, 1:26 am, Richard Vézina <ml.richard.vez...@gmail.com>
wrote:
> Maybe reading IS_IN_DB doc could helps...
>
> Richard
>
> On Tue, Feb 21, 2012 at 5:22 PM, Richard Vézina <ml.richard.vez...@gmail.com
>
>
>
>
>
>
>
> > wrote:
> > Ok by new style I mean this syntax :
>
> > db.dog.owner.requires = IS_IN_DB(db,*db.person.id*,'%(name)s')
>
> > Instead of :
>
> > db.dog.owner.requires = IS_IN_DB(db,* 'person.id'*, '%(name)s')

Bruno Rocha

unread,
Feb 22, 2012, 1:42:20 AM2/22/12
to web...@googlegroups.com


On Tue, Feb 21, 2012 at 8:22 PM, Richard Vézina <ml.richa...@gmail.com> wrote:
db.dog.owner.requires = IS_IN_DB(db,db.person.id, db.person(db.person.id).name)

Then if that is possible, why not :

db.dog.owner.requires = IS_IN_DB(db,db.person.id,'%s' % db.person(db.person.id).name db.othertable(db.person(db.person.id).fk_to_other_table_id).field_other_table)


Not possible, but this is possible:

db.dog.owner.requires = IS_IN_DB(db, db.person.id, lambda row: db(db.othertable.foreign_key == row.reference_key).select().first().somefield)

--

Ashraf Mansour

unread,
Feb 22, 2012, 3:08:37 AM2/22/12
to web2py-users
what about

query = ( db.person.id == db.othertable.id ) & xxx
xxx.requires = IS_IN_DB(db(query),'othertable.id',((( all fields of
othertable are accessible, no need for dot ))), xxx )

Ashraf

On Feb 22, 9:42 am, Bruno Rocha <rochacbr...@gmail.com> wrote:
> On Tue, Feb 21, 2012 at 8:22 PM, Richard Vézina <ml.richard.vez...@gmail.com
>
> > wrote:
> > db.dog.owner.requires = IS_IN_DB(db,db.person.id, db.person(db.person.id
> > ).name)
>
> > Then if that is possible, why not :
>
> > db.dog.owner.requires = IS_IN_DB(db,db.person.id,'%s' % db.person(
> > db.person.id).name db.othertable(db.person(db.person.id
> > ).fk_to_other_table_id).field_other_table)
>
> Not possible, but this is possible:
>
> db.dog.owner.requires = IS_IN_DB(db, db.person.id, *lambda row:
> db(db.othertable.foreign_key == row.reference_key
> ).select().first().somefield*)
Reply all
Reply to author
Forward
0 new messages