[CDBI] ordering a has_many() dataset from TT

Arshavir Grigorian grigorian at gmail.com
Mon Jun 18 22:29:10 BST 2007


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 at stanford.edu> 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
> >



More information about the ClassDBI mailing list