[Bast-commits] r6336 - in DBIx-Class/0.08: branches trunk/lib/DBIx/Class

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Tue May 19 17:43:00 GMT 2009


Author: ribasushi
Date: 2009-05-19 17:42:59 +0000 (Tue, 19 May 2009)
New Revision: 6336

Removed:
   DBIx-Class/0.08/branches/joined_count/
Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
Log:
Add files dropped by the screwed up merge - I suck

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-05-19 17:39:42 UTC (rev 6335)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSet.pm	2009-05-19 17:42:59 UTC (rev 6336)
@@ -1150,7 +1150,7 @@
 
 =cut
 
-my @count_via_subq_attrs = qw/join seen_join group_by/;
+my @count_via_subq_attrs = qw/join seen_join prefetch group_by/;
 sub count {
   my $self = shift;
   return $self->search(@_)->count if @_ and defined $_[0];
@@ -1173,14 +1173,21 @@
 
   my $attrs = { %{$self->_resolved_attrs} };
 
-  my $select_cols = $attrs->{group_by} || [ map { "$attrs->{alias}.$_" } ($self->result_source->primary_columns) ];
+  # copy for the subquery, we need to do some adjustments to it too
+  my $sub_attrs = { %$attrs };
+
+  # these can not go in the subquery either
+  delete $sub_attrs->{$_} for qw/prefetch select +select as +as columns +columns/;
+
+  # force a group_by and the same set of columns (most databases require this)
+  $sub_attrs->{columns} = $sub_attrs->{group_by} ||= [ map { "$attrs->{alias}.$_" } ($self->result_source->primary_columns) ];
+
   $attrs->{from} = [{
-    count_subq => $self->search ({}, { columns => $select_cols, group_by => $select_cols })
-                         ->as_query
+    count_subq => (ref $self)->new ($self->result_source, $sub_attrs )->as_query
   }];
 
-  # the subquery above will integrate everything, including 'where' and any pagers
-  delete $attrs->{$_} for (@count_via_subq_attrs, qw/where rows offset pager page/ );
+  # the subquery replaces this
+  delete $attrs->{where};
 
   return $self->__count ($attrs);
 }
@@ -1205,12 +1212,13 @@
 
   $attrs ||= { %{$self->{attrs}} };
 
+  # take off any subquery attrs (they'd be incorporated in the subquery),
+  # any column specs, any pagers, record_filter is cdbi, and no point of ordering a count
+  delete $attrs->{$_} for (@count_via_subq_attrs, qw/columns +columns select +select as +as rows offset page pager order_by record_filter/);
+
   $attrs->{select} = { count => '*' };
   $attrs->{as} = [qw/count/];
 
-  # take off any pagers, record_filter is cdbi, and no point of ordering a count
-  delete $attrs->{$_} for qw/rows offset page pager order_by record_filter/;
-
   my $tmp_rs = (ref $self)->new($self->result_source, $attrs);
   my ($count) = $tmp_rs->cursor->next;
 
@@ -1720,10 +1728,12 @@
   # with a subselect) to get the real total count
   my $count_attrs = { %$attrs };
   delete $count_attrs->{$_} for qw/rows offset page pager/;
-  my $total_count = (ref $self)->new($self->result_source, $count_attrs);
+  my $total_count = (ref $self)->new($self->result_source, $count_attrs)->count;
 
-  return $self->{pager} ||= Data::Page->new(
-    $total_count, $attrs->{rows}, $self->{attrs}{page}
+  return $self->{pager} = Data::Page->new(
+    $total_count,
+    $attrs->{rows},
+    $self->{attrs}{page}
   );
 }
 




More information about the Bast-commits mailing list