Now this makes sense. The book does not.

On Thursday, April 25, 2013 2:27:34 PM UTC-7, Anthony wrote:
>
> db.person.id.count() returns an Expression object. It generates SQL like 
> "COUNT(person.id)". When it is passed to the .select(), the count is 
> returned as one of the columns in the result. The key used to identify the 
> count column in each Row object of the result is the count SQL itself 
> (i.e., "COUNT(person.id)"), so you can access the count in each row via:
>
> row['COUNT(person.id)']
>
> However, the __str__ method of the Expression object will also return the 
> SQL, so you can instead do:
>
> row[str(count)]
>
> To make things even easier, if you pass an Expression object as the key to 
> a Row, it will automatically apply the __str__ method, so you can just do:
>
> row[count]
>
> which is the method used in the book example.
>
> Anthony
>
> On Thursday, April 25, 2013 3:55:46 PM UTC-4, Domagoj Kovač wrote:
>>
>> count = db.person.id.count()
>>
>> I understand this line of code, it is obvious that limitby clause here 
>> would be stupid.
>>
>> >>> for row in db(db.person.id==db.thing.owner_id).select(
>>         db.person.name, count, groupby=db.person.name):
>>         print row.person.name, row[count]
>> Alex 2
>> Bob 1
>>
>> I don't understand what is the purpose of the count here, and is this 
>> count related to the count above.
>>
>>
>>

-- 

--- 
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/groups/opt_out.


Reply via email to