parent=db.nodes.as('parent')
db((db.nodes.name=='child 2')&(db.nodes.parent_id==parent.id)).select
(parent.name)[0].name

On Jan 21, 2:28 pm, Oleg <[email protected]> wrote:
> Is there some better way to do the next task with DAL?
>
> db.define_table('nodes',
>                 SQLField('name'),
>                 SQLField('parent_id', 'reference nodes'))
>
> id1 = db.nodes.insert(name='root')
> id2 = db.nodes.insert(name='child 1', parent_id=id1)
> db.nodes.insert(name='child 2', parent_id=id2)
>
> now I wanna get the name of parent node of 'child 2'
>
> db(db(db.nodes.name=='child 2').select()[0].parent_id ==
> db.nodes.id).select()[0].name
>
> The problem is.. for that task it will be processed two sql query..
> with table aliases it is possible to make it only in one query..
> is it possible with current version of DAL?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to