Como retornar apenas um item apartir de uma busca no campo usando web2py

22 views
Skip to first unread message

Kimus

unread,
Aug 5, 2019, 9:51:27 AM8/5/19
to web2py-users
Ola , estou tentando fazer uma busca no banco usando db(db.table.id == request.vars.id).select()

só que esse select retorna uma lista/rows dai queria saber como retornar apenas um item, ja tentei usar o .firts() mas não ta funcionando direito

alguem teria alguma ideia 

Christian Varas

unread,
Aug 5, 2019, 11:53:40 AM8/5/19
to web...@googlegroups.com

Hi, why doesn't work good  with first() ?
 if you do: db(db.table.xx==request.vars.xx).select().first() it will return just the first record, if it doesn't is because the record does not exist.

other way to do this is with limitby:
db().select(db.person.ALL, limitby=(0, 2)):
http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#orderby-groupby-limitby-distinct-having-orderby_on_limitby-join-left-cache

Cheers.
--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/b61ac3fa-7ec5-4268-baaa-e9ad27c9f3f1%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages