norbi: Norbert Buchmuller <norbi@nix.hu>
+arcanez: Justin Hunter <justin.d.hunter@gmail.com>
+
=head1 LICENSE
You may distribute this code under the same terms as Perl itself.
# offset, order by, group by, where and page are not needed to count. record_filter is cdbi
delete $attrs->{$_} for qw/rows offset order_by group_by where page pager record_filter/;
- $self->result_source->resultset;
my $tmp_rs = (ref $self)->new($self->result_source, $attrs);
my ($count) = $tmp_rs->cursor->next;
return $count;
sub select {
my ($self, $table, $fields, $where, $order, @rest) = @_;
local $self->{having_bind} = [];
+
+# if (ref $table eq 'HASH') {
+# my $alias;
+# ($alias, $table) = %$table;
+# }
+
if (ref $table eq 'SCALAR') {
$table = $$table;
}
- elsif (ref $table eq 'HASH') {
- ## what if they want to alias a sub query?
- }
elsif (ref $table eq 'REF') {
- #my ($sql, @bind) = @{${$t}}; push(@{$self->{having_bind}}, @bind;);
- my $t = $table;
- $table = shift @$$t;
- while (my $b = shift @$$t) { push @{$self->{having_bind}}, $b; }
+ my ($sql, @bind) = @{${$table}};
+ push(@{$self->{having_bind}}, @bind);
+ $table = $sql;
}
elsif (not ref $table) {
$table = $self->_quote($table);
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use lib '/sporkrw/xfer/DBIx-Class/0.08/branches/count_distinct/lib';
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+eval "use DBD::SQLite";
+plan skip_all => 'needs DBD::SQLite for testing' if $@;
+plan tests => 4;
+
+cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }),
+ '==', 9, 'Count without DISTINCT ok');
+
+cmp_ok($schema->resultset("Tag")->count({ tag => [ 'Blue', 'Shiny' ] }, { group_by => 'tag' }),
+ '==', 2, 'Count with single column group_by ok');
+
+cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }, { group_by => [ qw/tag cd/ ]}),
+ '==', 4, 'Count with multiple column group_by ok');
+
+cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }, { distinct => 1 }),
+ '==', 4, "Count with single column distinct ok");
+