[CDBI] order by a foreign key

Hartmaier Alexander Alexander.Hartmaier at t-systems.at
Tue Aug 16 17:00:04 BST 2005


Use Class::DBI::Sweet ;-)
@array = My::Class->retrieve_all({ fieldname => 'value'});

-Alex


> -----Ursprüngliche Nachricht-----
> Von: classdbi-bounces at lists.digitalcraftsmen.net [mailto:classdbi-
> bounces at lists.digitalcraftsmen.net] Im Auftrag von Randal L. Schwartz
> Gesendet: Dienstag, 16. August 2005 17:48
> An: Marcello
> Cc: classdbi at lists.digitalcraftsmen.net
> Betreff: Re: [CDBI] order by a foreign key
> 
> >>>>> "Marcello" == Marcello  <m.romani at spinsoft.it> writes:
> 
> Marcello> I have two tables, 'cd' and 'artist', whose model classes are
> Marcello> MyApp::Cd and MyApp::Artist.
> 
> Marcello> MyApp::Artist is stringified as 'name'
> 
> Marcello> The relationship is:
> Marcello> MyApp:Cd->has_a( artist => MyApp::Artist );
> 
> Marcello> MyApp::Cd uses Class::DBI::Plugin::RetrieveAll, so I can say:
> Marcello> my @cds = MyApp::Cd->retrieve_all_sorted_by( $order ); # e.g.
> title ASC
> 
> Marcello> And now to the point:
> Marcello> if $order == 'artist' the @cds list gets ordered by the artist
> *id*,
> Marcello> not by the artist name.
> 
> Marcello> What I would like to obtain is a list ordered by the foreign
> class's
> Marcello> 'stringify' column.
> 
> Dunno how to do it with that plugin, but using this little trick
> I came across one day...
> 
> my @ordered_cds = map $_->[0],
>   sort { $a->[1] cmp $b->[1] }
>   map [$_, $_->artist->stringify], MyApp::Cd->retrive_all;
> 
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
> 0095
> <merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
> training!
> 
> _______________________________________________
> ClassDBI mailing list
> ClassDBI at lists.digitalcraftsmen.net
> http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5544 bytes
Desc: not available
Url : http://lists.digitalcraftsmen.net/mailman/private/classdbi/attachments/20050816/a990b073/smime.bin


More information about the ClassDBI mailing list