[web2py] Re: Reverse relationships

2018-04-16 Thread Anthony


On Monday, April 16, 2018 at 11:47:28 AM UTC-4, Leonel Câmara wrote:
>
> Note that in web2py you can actually do something like this:
>
> db.define_table('tag', Field('name'))
>
> db.define_table('debate'. Field('title'))
>
> db.define_table('debate_tag', Field('tag', 'reference tag'), 
> Field('debate', 'reference debate'))
>
> Then say you want to know the tags debate with id 1 has
>
> db.debate[1].debate_tag.select()
>

Also, note that db.debate[1].debate_tag is a DAL Set object, which can be 
called and passed an additional query to further refine the results:

db.debate[1].debate_tag((db.debate_tag.tag == db.tag.id) & (db.tag.name.
startswith('a')).select(db.tag.name)

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Reverse relationships

2018-04-16 Thread Leonel Câmara
Note that in web2py you can actually do something like this:

db.tag(Field('name'))

db.debate(Field('title'))

db.debate_tag(Field('tag', 'reference tag'), Field('debate', 'reference 
debate'))

Then say you want to know the tags debate with id 1 has

db.debate[1].debate_tag.select()

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.