As other has said select().first() is an alias for select()[0]. This means
that web2py is still fetching and parsing all the matching rows even if you
only need one. So make sure you do
db(...).select(limitby=(0,1)).first()
so you only fetch and parse the one that you want if it exists.
On Friday, 6 February 2015 13:18:13 UTC-6, Alex Glaros wrote:
>
> can someone please consolidate my knowledge or tell me where in
> documentation this is explained
>
> the "first()" in this line below:
>
> this_message = db(db.InternalMessage.id ==
> request.get_vars.filter).select()*.first()*
>
> allows below to work in view:
>
> {{=this_message.created_by.last_name}}
>
> if the ".first()" is removed leaving this:
>
> this_message = db(db.InternalMessage.id == request.get_vars.filter).
> *select()*
>
> then view no longer works. First result is a single row, second result can
> be many rows.
>
> What is this concept called?
>
> Is first result a dictionary and second result a row?
>
> I understand that there is unacceptable ambiguity in the 2nd result with
> many possible rows but would like to know what the terms are called and
> where documented so I can read about it.
>
> Is .first() the only/best way to get a value into a single var (when no
> looping is necessary)?
>
> thanks
>
> Alex Glaros
>
--
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.