[Dbix-class] Re: Complex(ish) select statement => DBIx::Class method

Rob Kinyon rob.kinyon at gmail.com
Fri Mar 13 13:23:18 GMT 2009


On Thu, Mar 12, 2009 at 14:27, David Ihnen <davidi at norchemlab.com> wrote:
> I think that makes it more clear.  Given the proper relationships set up
> couldn't that just be something like...
>
> sub elapsed_ms {
> my $self = shift;
> my $id = shift;
> $self->search(
>   { me.id => $id },
>   { +select => [ \"datediff(millisecond, logparents.date, logstatus.date)" ]
>   , +as => [ elapsed ]
>   , prefetch => [ 'logstatus', 'logchildren' ]
>   , order_by => 'logstatus.date desc'
>   })->first->get_column->('elapsed');
> }

Use join instead of prefetch unless you actually need the
optimization. In this case, you don't.

Prefetch still has some bugs in it that rear their ugly heads in odd places.

Rob



More information about the DBIx-Class mailing list