[CDBI] order by a foreign key

Marcello m.romani at spinsoft.it
Tue Aug 16 17:47:19 BST 2005

Matt S Trout ha scritto:
> On Tue, Aug 16, 2005 at 05:34:23PM +0200, Marcello wrote:
>>Hallo everybody,
>>    I'm working with Class-DBI in a catalyst project, and I found a 
>>problem that I think is not directly related to Catalyst, but to 
>>Class-DBI (or perhaps to Class::DBI::Plugin::RetrieveAll).
>>Let me first describe the scenario:
>>I have two tables, 'cd' and 'artist', whose model classes are MyApp::Cd 
>>and MyApp::Artist.
>>MyApp::Artist is stringified as 'name'
>>The relationship is:
>>MyApp:Cd->has_a( artist => MyApp::Artist );
>>MyApp::Cd uses Class::DBI::Plugin::RetrieveAll, so I can say:
>>my @cds = MyApp::Cd->retrieve_all_sorted_by( $order ); # e.g. title ASC
> Try Class::DBI::Sweet as a base instead of Class::DBI and
> MyApp::Cd->search({ }, { prefetch => 'artist', order_by => 'artist.name' });
> That should do the trick - and return your $cd->artist objects prepopulated
> ala ActiveRecord's :include to boot.

Dunno about ActiveRecord's way of doing things :-) but I think this 
might be a good time for me to eventually try out CDBI::Sweet.

Thanks everybody for your replies.


More information about the ClassDBI mailing list