[CDBI] How to sort "has_many" relation after I've declared it?
David McMath <mcdave-FGKo4X94FMn2fBVCVOL8/[email protected]> Mon, 20 Aug 2012 15:45:08 -0500
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
Dear List,
In the documentation, the example is given of
Music::CD->has_many( tracks => 'Music::Track', { order_by =>
'playorder' }) ;
so if I do
my @t = $cd->tracks
then @t is ordered by "playorder".
If one had been short-sighted and instead just declared
Music::CD->has_many( tracks => 'Music::Track' ) ;
are there any magical arguments (or something) one could pass to
$cd->tracks() to sort the results? I want to do the sorting on the
database side (which could well be a bad idea, but that's an empirical
question).
In my particular case (which is basically the same as the Music::CD
case, so I don't bother listing it), my naive attempt was to just ask:
my (@s) = $d->schools( { order_by => 'name' } ) ;
but got the message
order_by is not a column of School at
/usr/lib/perl5/site_perl/5.8.8/Class/DBI/Search/Basic.pm line 115.
The implementation of HasMany seems to have some logic for adding an
order_by clause to the search, but it only seems to draw that from
$class->meta_info.
Thansk for any advice,
dave