return $alias2source;
}
-sub _trim_attributes_for_count {
+sub _copy_attributes_for_count {
my ($self, $source, $attrs) = @_;
my %attrs = %$attrs;
sub count {
my ($self, $source, $attrs) = @_;
- my $tmp_attrs = $self->_trim_attributes_for_count($source, $attrs);
+ my $tmp_attrs = $self->_copy_attributes_for_count($source, $attrs);
# overwrite the selector
$tmp_attrs->{select} = { count => '*' };
my $offset = $attrs->{offset} || 0;
my $total = $attrs->{rows} + $offset;
- my $new_attrs = $self->_trim_attributes_for_count($source, $attrs);
- $new_attrs->{select} = '1';
- $new_attrs->{as} = ['dummy'];
+ my $new_attrs = $self->_copy_attributes_for_count($source, $attrs);
+
+ my $first_pk = ($source->primary_columns)[0];
+
+ $new_attrs->{select} = $first_pk ? "me.$first_pk" : 1;
my $tmp_rs = $source->resultset_class->new($source, $new_attrs);