[Bast-commits] r8062 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class
t/count t/prefetch
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Thu Dec 10 08:53:38 GMT 2009
Author: ribasushi
Date: 2009-12-10 08:53:38 +0000 (Thu, 10 Dec 2009)
New Revision: 8062
Modified:
DBIx-Class/0.08/trunk/Changes
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
DBIx-Class/0.08/trunk/t/count/prefetch.t
DBIx-Class/0.08/trunk/t/prefetch/via_search_related.t
Log:
First half of distinct cleanup
Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes 2009-12-10 08:36:21 UTC (rev 8061)
+++ DBIx-Class/0.08/trunk/Changes 2009-12-10 08:53:38 UTC (rev 8062)
@@ -5,6 +5,7 @@
in order_by also need to be aded to the resulting group_by)
- Do not attempt to deploy FK constraints pointing to a View
- Fix count/objects from search_related on limited resultset
+ - Stop propagating distinct => 1 over search_related chains
- Make sure populate() inherits the resultset conditions just
like create() does
- Make get_inflated_columns behave identically to get_columns
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2009-12-10 08:36:21 UTC (rev 8061)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm 2009-12-10 08:53:38 UTC (rev 8062)
@@ -2626,7 +2626,7 @@
# ->_resolve_join as otherwise they get lost - captainL
my $join = $self->_merge_attr( $attrs->{join}, $attrs->{prefetch} );
- delete @{$attrs}{qw/join prefetch collapse select as columns +select +as +columns/};
+ delete @{$attrs}{qw/join prefetch collapse distinct select as columns +select +as +columns/};
my $seen = { %{ (delete $attrs->{seen_join}) || {} } };
Modified: DBIx-Class/0.08/trunk/t/count/prefetch.t
===================================================================
--- DBIx-Class/0.08/trunk/t/count/prefetch.t 2009-12-10 08:36:21 UTC (rev 8061)
+++ DBIx-Class/0.08/trunk/t/count/prefetch.t 2009-12-10 08:53:38 UTC (rev 8062)
@@ -54,19 +54,15 @@
FROM (
SELECT genre.genreid
FROM (
- SELECT cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track
- FROM (
- SELECT me.artistid, me.name, me.rank, me.charfield
- FROM artist me GROUP BY me.artistid, me.name, me.rank, me.charfield
- ) me
- LEFT JOIN cd cds ON cds.artist = me.artistid
- GROUP BY cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track
- ) cds
+ SELECT me.artistid, me.name, me.rank, me.charfield
+ FROM artist me GROUP BY me.artistid, me.name, me.rank, me.charfield
+ ) me
+ JOIN cd cds ON cds.artist = me.artistid
JOIN genre genre ON genre.genreid = cds.genreid
LEFT JOIN cd cds_2 ON cds_2.genreid = genre.genreid
- WHERE ( genre.name = ? )
- GROUP BY genre.genreid
- ) count_subq
+ WHERE ( genre.name = ? ) GROUP BY genre.genreid
+ )
+ count_subq
)',
[ [ 'genre.name' => 'emo' ] ],
);
Modified: DBIx-Class/0.08/trunk/t/prefetch/via_search_related.t
===================================================================
--- DBIx-Class/0.08/trunk/t/prefetch/via_search_related.t 2009-12-10 08:36:21 UTC (rev 8061)
+++ DBIx-Class/0.08/trunk/t/prefetch/via_search_related.t 2009-12-10 08:53:38 UTC (rev 8062)
@@ -109,27 +109,31 @@
is($rs->search_related('cds')->count, 4, 'prefetch without distinct (count)');
- $rs = $artist_rs->search(undef, {distinct => 1})
- ->search_related('cds')->search_related('genre',
+ $rs = $artist_rs->search_related('cds', {}, { distinct => 1})->search_related('genre',
{ 'genre.name' => 'vague genre' },
);
+ is($rs->all, 2, 'distinct does not propagate over search_related (objects)');
+ is($rs->count, 2, 'distinct does not propagate over search_related (count)');
+
+ $rs = $rs->search ({}, { distinct => 1} );
is($rs->all, 1, 'distinct without prefetch (objects)');
is($rs->count, 1, 'distinct without prefetch (count)');
- $rs = $artist_rs->search({}, {distinct => 1})
- ->search_related('cds')->search_related('genre',
+ $rs = $artist_rs->search_related('cds')->search_related('genre',
{ 'genre.name' => 'vague genre' },
- { prefetch => 'cds' },
+ { prefetch => 'cds', distinct => 1 },
);
is($rs->all, 1, 'distinct with prefetch (objects)');
is($rs->count, 1, 'distinct with prefetch (count)');
+
+ TODO: {
+ local $TODO = "This makes another 2 trips to the database, it can't be right";
# artist -> 2 cds -> 2 genres -> 2 cds for each genre + distinct = 2
is($rs->search_related('cds')->all, 2, 'prefetched distinct with prefetch (objects)');
is($rs->search_related('cds')->count, 2, 'prefetched distinct with prefetch (count)');
+ }
-
-
}, 'distinct generally works with prefetch on deep search_related chains');
done_testing;
More information about the Bast-commits
mailing list