row = my_phones.find(lambda r: r.id == 3)[0]

Note, .find() is a Python function, so this will indeed iterate over the 
rows of my_phones. If my_phones is large, it may actually be more efficient 
to simply issue a separate query to the database to retrieve that one 
record.

Anthony

On Saturday, April 19, 2014 4:12:13 PM UTC-4, Kurt Jensen wrote:

> How can I get a row from a DAL object if I know the associated id.
>
> Example:
>
> my_phones=db((db.prof_phone.pid==person_id)&(db.prof_phone.provider>1)).
> select(db.prof_phone.ALL,db.provider.edomain,
>        left=db.provider.on(db.provider.id==db.prof_phone.provider),orderby
> =db.prof_phone.label)
>
> Which gets me this object:
> my_phones : 
> prof_phone.id prof_phone.label prof_phone.phone prof_phone.provider 
> provider.edomain
> 2         Cell                 (360) 123-9876         2                
> vmobl.com<http://www.google.com/url?q=http%3A%2F%2Fvmobl.com&sa=D&sntz=1&usg=AFQjCNFj8FM0kyhXWRSIG9qTH4q3sJTFPA>
> 3         Wife Cell        (360) 123-4567         2                
> vmobl.com
>
> Now I want the data from the second row of the object which I know has the 
> prof_phone.id of 3.
>
> Like: Wife Cell, (360) 123-4567, vmobl.com
>
> How do I get that data out of the object without iterating over eveything?
>
>

-- 
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.

Reply via email to