Re: [CDBI] order by a foreign key
[prev]
[thread]
[next]
[Date index for 2005/08/16]
On Tue, Aug 16, 2005 at 06:47:19PM +0200, Marcello wrote:
> 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.
ActiveRecord makes different mistakes to Class::DBI, but prefetch isn't
one of them given it solves the 1+100 queries issue.
Class::DBI::Sweet attempts to correct some of the mistakes of Class::DBI
without introducing too many of its own; DBIx::Class is gradually evolving
towards making its whole own new set of mistakes, but hopefully makes very
few of the same ones as Class::DBI or ActiveRecord :)
--
Matt S Trout Website: http://www.shadowcatsystems.co.uk
Technical Director E-mail: mst (at) shadowcatsystems.co.uk
Shadowcat Systems Ltd.
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi