From: Peter Rabbitson Date: Tue, 19 May 2009 18:46:40 +0000 (+0000) Subject: Simplify __count() - explicitly specify which attributes to copy, instead of deleting... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1abd23e08caca12dd0093b7fa6ab82917392555e;p=dbsrgits%2FDBIx-Class-Historic.git Simplify __count() - explicitly specify which attributes to copy, instead of deleting a whole bunch of them --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index e0bd00b..f840146 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1150,7 +1150,7 @@ on the resultset and counts the results of that. =cut -my @count_via_subq_attrs = qw/join seen_join prefetch group_by/; +my @count_via_subq_attrs = qw/join seen_join prefetch group_by having/; sub count { my $self = shift; return $self->search(@_)->count if @_ and defined $_[0]; @@ -1212,9 +1212,8 @@ sub __count { $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/); + # these are the only attributes that actually matter for count + $attrs = { map { exists $attrs->{$_} ? ( $_ => $attrs->{$_} ) : () } qw/where bind alias from from_bind/ }; $attrs->{select} = { count => '*' }; $attrs->{as} = [qw/count/];