Re: [web2py] Re: Shortcut for fetching a row
There is this important rule that all programers must respect: write code YOU can understand. Khalil
[web2py] Re: Shortcut for fetching a row
DenesL, That works and just what I need. Thank you! Anthony, I did think that the first argument is the field to return :) Thank you for the clear explanation. Khalil, Thanks for the tips. I'd consider that for my projects.
Re: [web2py] Re: Shortcut for fetching a row
Hi, This is why I almost never use shortcuts. When something goes wrong and you have poeple waiting for you to resolve the problem so they can get back to work, you always dont have enough attention to decrypt shortcuts. Khalil
[web2py] Re: Shortcut for fetching a row
On Friday, November 18, 2011 3:31:21 AM UTC-5, Cahya Dewanta wrote: > > According to the book, for what I understand > > record = db(db.owner.name=='test').select(db.owner.id).first() > could be shortcut with > record = db.owner(id, name='test') > > But the latter return None. How can I shortcut the first statement > properly? > Perhaps the book could be more clear. record = db.owner(id, name='test') is a shortcut for: record = db((db.owner.id == id) & (db.owner.name == 'test')).select().first() In other words, the first argument to db.owner(...) can simply be the id of the record you want to fetch. It does not represent the name of the field you want to return. Anthony
[web2py] Re: Shortcut for fetching a row
On Nov 18, 3:31 am, Cahya Dewanta wrote: > According to the book, for what I understand > > record = db(db.owner.name=='test').select(db.owner.id).first() > could be shortcut with > record = db.owner(id, name='test') record = db.owner(name='test') # if you want just the id do record = db.owner(name='test').id > But the latter return None. How can I shortcut the first statement > properly? > > Thank you so very much.