[Dbix-class] Counting one to many

Rob Kinyon rob.kinyon at gmail.com
Mon Jun 29 22:15:23 GMT 2009


The reason for this is because TT provides an implicit list context to
all methods. This is why the _rs methods exist. It should be your
first stab when solving a problem in TT.

2009/6/29 Dan Horne <dan.horne at redbone.co.nz>:
> Brilliant - exactly what I was after
>
>
> On 30/06/2009, at 09:52 AM, Rob Kinyon wrote:
>
>> invoice.invoice_lines_rs.count
>>
>> Rob
>>
>> On Mon, Jun 29, 2009 at 17:48, Dan Horne<dan.horne at redbone.co.nz> wrote:
>>>
>>> Hi
>>>
>>> Say I have two tables, invoices and invoice_lines, where the relationship is
>>> one to many. If we pass a resultset of the invoices to a TT template, is it
>>> possible to chain an a method on the resultset to get a count of he invoice
>>> lines? I don't mind going back to the db to do exta fetches per line as
>>> there will never be more than 20 invoices. i.e., I want to do something like
>>> this:
>>>
>>>       [% WHILE (invoice = invoices.next) %]
>>>       <tr>
>>>           <td>[% invoice.invoice_number %]</td>
>>>           <td>[% invoice.invoice_lines.count %]</td> <-- something that
>>> does this
>>>       </tr>
>>>       [% END %]
>>>
>>> Regards
>>>
>>> Dan
>>>
>>>
>>> _______________________________________________
>>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>>> IRC: irc.perl.org#dbix-class
>>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>>> Searchable Archive:
>>> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>>>
>>
>>
>>
>> --
>> Thanks,
>> Rob Kinyon
>>
>> _______________________________________________
>> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>> IRC: irc.perl.org#dbix-class
>> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>



-- 
Thanks,
Rob Kinyon



More information about the DBIx-Class mailing list