Hi,
Is it possible to create an alias referencing to a part of table?
Below is an example code. I would like the "host" alias to reference to the
participant table but only where role=='host'. Then I wouldn't need to
specify this condition every time I use the "host" alias.
db.define_table('party',
Field('place'))
db.define_table('participant',
Field('party_id', 'reference party'),
Field('name'),
Field('role'))
db.party.insert(place="Jane's home")
db.participant.insert(name='Jane',party_id=1,role='host')
db.participant.insert(name='George',party_id=1,role='organizer')
db.participant.insert(name='John',party_id=1,role='guest')
db.participant.insert(name='Mary',party_id=1,role='guest')
host = db.participant.with_alias('host')
organizer = db.participant.with_alias('organizer')
rows = db().select(
db.party.place,
host.name,
organizer.name,
left=(
host.on((host.party_id==db.party.id) & (host.role=='host')),
organizer.on((organizer.party_id==db.party.id) &
(organizer.role=='organizer'))
))
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.