[Dbix-class] Joining for counts of related items.

Bill Moseley moseley at hank.org
Fri Apr 23 22:09:00 GMT 2010


Back to my Music database.  In my Cd class I have these methods to return
counts of tracks of a specific type.


sub foo_track_type_count {
    return shift->tracks( { track_type =3D> 1 } )->count;  # any different
then count_related??
}

sub bar_track_type_count {
   return shift->tracks( { track_type =3D> { -in =3D> [2,3] } } )->count;
}


Now, it turns out that I always need these counts.

$cd =3D> $schema->resultset( 'Cd' )->find( $id );  # one database select
my $foos =3D $cd->foo_track_count;  # second select
my $bars =3D $cd->bar_track_count;  # third.


I know I can build a resultset that includes a total count (as seen in the
Cookbook), but is there a way to include counts that are limited to those
specific "track_types"?

IIRC from past discussions this had to be done with a custom FROM which then
broke some other functionality.



-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100423/25e=
f6ea7/attachment.htm


More information about the DBIx-Class mailing list