[Bast-commits] r6389 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Sat May 23 20:59:18 GMT 2009
Author: ribasushi
Date: 2009-05-23 20:59:17 +0000 (Sat, 23 May 2009)
New Revision: 6389
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/trunk/t/60core.t
Log:
Extra test and count fixes for prefetch + distinct
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2009-05-23 20:48:06 UTC (rev 6388)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2009-05-23 20:59:17 UTC (rev 6389)
@@ -1171,6 +1171,14 @@
# if needed force a group_by and the same set of columns (most databases require this)
if ($add_group_by) {
+
+ # if we prefetch, we group_by primary keys only as this is what we would get out of the rs via ->next/->all
+ # simply deleting group_by suffices, as the code below will re-fill it
+ # Note: we check $attrs, as $sub_attrs has collapse deleted
+ if (ref $attrs->{collapse} and keys %{$attrs->{collapse}} ) {
+ delete $sub_attrs->{group_by};
+ }
+
$sub_attrs->{columns} = $sub_attrs->{group_by} ||= [ map { "$attrs->{alias}.$_" } ($self->result_source->primary_columns) ];
}
Modified: DBIx-Class/0.08/trunk/t/60core.t
===================================================================
--- DBIx-Class/0.08/trunk/t/60core.t 2009-05-23 20:48:06 UTC (rev 6388)
+++ DBIx-Class/0.08/trunk/t/60core.t 2009-05-23 20:59:17 UTC (rev 6389)
@@ -5,10 +5,11 @@
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
+use DBIC::SqlMakerTest;
my $schema = DBICTest->init_schema();
-plan tests => 103;
+plan tests => 106;
eval { require DateTime::Format::MySQL };
my $NO_DTFM = $@ ? 1 : 0;
@@ -228,6 +229,20 @@
is ($collapsed_or_rs->all, 4, 'Collapsed joined search with OR returned correct number of rows');
is ($collapsed_or_rs->count, 4, 'Collapsed search count with OR ok');
+my $pref_or_rs = $collapsed_or_rs->search ({}, { prefetch => [qw/tags/] });
+is_same_sql_bind (
+ $pref_or_rs->as_query,
+ '(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, tags.tagid, tags.cd, tags.tag FROM cd me LEFT JOIN tags tags ON tags.cd = me.cdid WHERE ( ( tags.tag = ? OR tags.tag = ? ) ) GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, tags.tagid, tags.cd, tags.tag ORDER BY cdid, tags.cd, tags.tag)',
+ [
+ [ 'tags.tag' => 'Cheesy' ],
+ [ 'tags.tag' => 'Blue' ],
+ ],
+ 'Prefetch + distinct resulted in correct group_by',
+);
+is ($pref_or_rs->all, 4, 'Prefetched grouped search with OR returned correct number of rows');
+is ($pref_or_rs->count, 4, 'Prefetched grouped count with OR ok');
+
+
{
my $tcount = $schema->resultset('Track')->search(
{},
More information about the Bast-commits
mailing list