[Dbix-class] count behaviour

Ash Berlin ash_cpan at firemirror.com
Tue Feb 26 11:48:38 GMT 2008


On 26 Feb 2008, at 11:34, Alex Povolotsky wrote:

> Ash Berlin wrote:
>>
>> On 26 Feb 2008, at 11:23, Alex Povolotsky wrote:
>>
>>> Hello!
>>>
>>> I'm using (with Catalyst and TT) some simple code to count related  
>>> data
>>>
>>> [% FOREACH loc IN llist -%]
>>> <li>[% loc.name %] : (<a href="[% Catalyst.uri_for("edit/ 
>>> $loc.lid") %]>Edit</a>)
>>> [% loc.contacts.count+0 %] contacts (more): [% loc.servers.count+0  
>>> %] servers (more):
>>> here will be traffic
>>> [% END -%]
>>>
>>> Debugging SQL requests, I've found that both counts use "select *"  
>>> instead of "select count(*)".
>>>
>>> Is it a bug or a feature? Maybe count should be better optimized?
>>>
>>> Alex.
>>>
>>
>> TT calls everything i list context. So that count method is  
>> actually TT's count vmethod.
>>
>> you want [% loc.contacts_rs.count %] to get SELECT COUNT(*) executed.
>
> Whooops... where is it documented?...
>
> Alex.
>

I lied. there is no count vemthod - which is why you needed the +0

As for where its documened... somewhere in the Template Toolkit  
manual. the _rs methods are mentioned in Relationship docs of DBIC.

Tho it could be more obvious, since currently there is just this  
snippet (and ones like it)

> Return Value: $resultset (scalar context), @row_objs (list context)

Might be nice if you prepare a doc patch stating more explicitly what  
happens when you call a method which would normally return an RS in  
scalar context (search, my_rels, etc.) in list context, with  
particularly mention of Template Toolkit (which calls *everything* in  
list context.

Ash
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080226/7800cc6e/attachment.htm


More information about the DBIx-Class mailing list