Re: [CDBI] order by a foreign key

[prev] [thread] [next] [Date index for 2005/08/16]

From: Marcello
Subject: Re: [CDBI] order by a foreign key
Date: 16:47 on 16 Aug 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.

Marcello


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] order by a foreign key
Marcello 15:34 on 16 Aug 2005

Re: [CDBI] order by a foreign key
merlyn (Randal L. Schwartz) 15:48 on 16 Aug 2005

Re: [CDBI] order by a foreign key
Marcello 16:44 on 16 Aug 2005

Re: [CDBI] order by a foreign key
Hartmaier Alexander 16:00 on 16 Aug 2005

Re: [CDBI] order by a foreign key
Matt S Trout 16:08 on 16 Aug 2005

Re: [CDBI] order by a foreign key
Marcello 16:47 on 16 Aug 2005

Re: [CDBI] order by a foreign key
Matt S Trout 17:04 on 16 Aug 2005

Re: [CDBI] order by a foreign key
Marcello 07:33 on 17 Aug 2005

Generated at 13:17 on 19 Aug 2005 by mariachi v0.52