Re: [CDBI] ordering a has_many() dataset from TT
Marco Wise <marco.wise-FGKo4X94FMn2fBVCVOL8/[email protected]> Mon, 18 Jun 2007 15:22:33 -0700
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
If it's a date, it's probably best to use order_by in the definition of the CDBI class. - marco On Jun 18, 2007, at 2:29 PM, Arshavir Grigorian wrote: > Marco, > > Thanks. Both methods seem to work fine though I am not sure how sort > is able to handle database date fields. > > Arshavir > > > > On 6/18/07, Marco Wise <marco.wise-FGKo4X94FMn2fBVCVOL8/[email protected]> wrote: >> Hi Arshavir, >> >> Have you tried TT's sort vmethod? >> >> http://www.template-toolkit.org/docs/default/Manual/VMethods.html >> >> It would look like: >> >> [% FOREACH com IN contact.communications.sort('create_dt') %] >> >> I'm not sure what the create_dt field holds, but if it's numbers, you >> would use nsort instead of sort. >> >> This will fetch the results, then order them using TT. >> >> If you are always going to get the communications ordered by >> 'create_dt', you can move "order_by => 'create_dt' in your definition >> of Contact instead. >> >> See: http://search.cpan.org/dist/Class-DBI/lib/Class/DBI.pm#Ordering >> >> Probably something along the lines of: >> >> Contact->has_many(communications => 'Communication', { order_by => >> 'create_dt'}); >> >> - marco >> >> On Jun 18, 2007, at 1:37 PM, Arshavir Grigorian wrote: >> >> > Hi, >> > >> > I am calling a method on an existing object to return a list of >> > communications associate with it. (1:M - has_many()). However, >> when I >> > try to sort the resulting dataset by a column in the >> "communication" >> > table, like so (in TT) >> > >> > [% FOREACH com IN contact.communications({ order_by => >> > 'create_dt' }) %] >> > >> > I get the following error. >> > >> > [Mon Jun 18 13:33:16 2007] [error] Error Processing the template: >> > undef error - order_by is not a column of Communication at >> > /usr/local/share/perl/5.8.7/Class/DBI/Search/Basic.pm line 115\n >> > [Mon Jun 18 13:33:16 2007] [error] >> > >> > Please let me know if there is another way to accomplish this. >> > >> > TIA. >> > >> > >> > Arshavir >> >