[Dbix-class] MySql distinct count fix
Peter Rabbitson
rabbit+dbic at rabbit.us
Sun Jun 7 21:21:40 GMT 2009
Anthony Gladdish wrote:
> Hi,
>
> Using DBIC v0.08102_07.
>
> My Result class relationships:
>
> 1. Course.pm
> 2. Event.pm:
> __PACKAGE__->belongs_to( 'course' => 'Course', 'based_on' );
>
> My test:
>
> my $search;
> push( @$search, ('me.code', { 'like', '%i1%' } ) );
> my $rs = $schema->resultset('Event')->search(
> {
> -or => $search,
> },
> {
> distinct => 1,
> prefetch => 'course',
> }
> );
> is $rs->count, 1, '$rs ok';
>
> Fails with:
>
> DBIx::Class::ResultSet::count(): DBI Exception: DBD::mysql::st execute failed: Duplicate column name 'id' [for Statement "SELECT COUNT( * ) FROM (SELECT me.id, me.code, me.start, me.hours, me.end, me.leader, me.based_on, me.attend_max, me.created_by, me.attend_min, me.RT_ticket, me.status, me.created, me.location, me.price_1, me.price_2, me.price_3, me.price_4, me.price_5, course.id, course.title, course.topics, course.tasks, course.prerequisites, course.overview, course.target, course.quotes, course.code, course.hours, course.sub_title, course.further_tasks, course.short_desc, course.shorter_desc FROM event me JOIN event_defaults course ON course.id = me.based_on WHERE ( me.code LIKE ? ) GROUP BY me.id, me.code, me.start, me.hours, me.end, me.leader, me.based_on, me.attend_max, me.created_by, me.attend_min, me.RT_ticket, me.status, me.created, me.location, me.price_1, me.price_2, me.price_3, me.price_4, me.price_5, course.id, course.title, course.topics, course.tasks, cou
rse.prerequisites, course.overview, course.target, course.quotes, course.code, course.hours, course.sub_title, course.further_tasks, course.short_desc, course.shorter_desc) count_subq" with ParamValues: 0='%i1%']
>
> Passes, if I comment out either "distinct" or "prefetch" but this is undesired.
>
> Am I doing anything wrong?
> Has this been fixed in a newer RC yet that I can test?
>
Fixed in http://dev.catalyst.perl.org/svnweb/bast/revision/?rev=6537
More information about the DBIx-Class
mailing list