[Dbix-class] order_by question

Rob Kinyon rob.kinyon at gmail.com
Wed Jan 19 19:26:58 GMT 2011


What happened? Why do you think that doesn't work? Please provide what
should have happened, what did happen, and why you're not happy with
the outcome.

Rob

On Wed, Jan 19, 2011 at 13:28, africroissance <africroissance at gmail.com> wrote:
> Hello,
> I am very very new to using DBIx::Class -- please do forgive the naiveté of
> the question - I have a question about using the order_by attribute.
>
> Given the simple example in the CPAN docs:
> http://search.cpan.org/~danieltwc/DBIx-Class-0.07002/lib/DBIx/Class/Manual/Example.pod
>
> What would be the right syntax to get back a list of CDs ordered by the
> number of tracks each has? I thought something like the following would work
> but I was wrong:
>
> sub get_cds_ordered_by_number_of_tracks {
>   print "CDS ordered by the number of tracks they have\n";
>   my $rs = $schema->resultset('Cd')->search(
>     {},
>     {
>       order_by => \'tracks.count DESC',
>       join     => [qw/ tracks /],
>     }
>   );
>   while (my $cd = $rs->next) {
>     print $cd->title . "\n";
>   }
>   print "\n";
> }
>
> Thank you very much.
> _______________________________________________
> 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