[Dbix-class] as_query() and DBIx::Class::Cursor::Cached aren't friends

Peter Rabbitson rabbit+dbic at rabbit.us
Mon Jun 8 00:36:19 GMT 2009


Aran Deltac wrote:
> Just recently I upgraded DBIx::Class from 0.08010 to 0.08103 and am
> getting errors about as_query() and DBIx::Class::Cursor::Cached.
> Here's what the error is:
> 
> Couldn't render component "/earnings_history/earnings_history.mhtml" -
> error was "Can't locate object method "as_query" via package
> "DBIx::Class::Cursor::Cached" at
> /vcm/home/lib/site_perl/DBIx/Class/ResultSet.pm line 2006, <DATA> line
> 228.
> Stack:
>   [/vcm/home/lib/site_perl/DBIx/Class/ResultSet.pm:2006]
>   [/vcm/home/lib/site_perl/DBIx/Class/ResultSet.pm:1199]
>   [/vcm/home/lib/site_perl/DBIx/Class/ResultSet.pm:1170]
>   [/vcm/home/component/ui/mason/pub/earnings_history/earnings_history.mhtml:12]
>   [/vcm/home/component/ui/mason/pub/autohandler:83]
>   [/vcm/home/component/ui/mason/shared/setup.cmp:10]"
> 
> Line 12 of earnings_history.mhtml is this:
> 
> %   my $perc = sprintf("%.1f", 100 / ($media_types->count()+3) );
> 
> So, somehow a simple ->count() on a cached resultset causes the latest
> DBIC to use as_query, which DBIx::Class::Cursor::Cached.
> 
> Any thoughts?  Easy fix?  Need any more details?
> 

If a resultset has either group_by or collapse set by has_many prefetch
(which is a group_by in a sense) - then we use a subquery to get the
proper count. The as_query method was implemented on the Cursor at the
time it was written (not sure why, I wasn't the implementer). So now
that you have a different cursor, it doesn't return the SQL DBIC needs
in order to construct the subquery.

The fix should be quite simple, i.e. move as_query out of the Cursor
class. But first I'd like someone to comment on why it ended up there
in the first place.

Cheers



More information about the DBIx-Class mailing list