} @$fields);
} elsif ($ref eq 'HASH') {
foreach my $func (keys %$fields) {
+ if ($func eq 'distinct') {
+ my $_fields = $fields->{$func};
+ if (ref $_fields eq 'ARRAY' && @{$_fields} > 1) {
+ die "Unsupported syntax, please use " .
+ "{ group_by => [ qw/" . (join ' ', @$_fields) . "/ ] }" .
+ " or " .
+ "{ select => [ qw/" . (join ' ', @$_fields) . "/ ], distinct => 1 }";
+ }
+ else {
+ warn "This syntax will be deprecated in 09, please use " .
+ "{ group_by => '${_fields}' }" .
+ " or " .
+ "{ select => '${_fields}', distinct => 1 }";
+ }
+ }
+
return $self->_sqlcase($func)
.'( '.$self->_recurse_fields($fields->{$func}).' )';
}
use warnings;
use Test::More;
+use Test::Exception;
use lib qw(t/lib);
eval "use DBD::SQLite";
plan skip_all => 'needs DBD::SQLite for testing' if $@;
-plan tests => 16;
+plan tests => 18;
# The tag Blue is assigned to cds 1 2 3 and 5
# The tag Cheesy is assigned to cds 2 4 and 5
$rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Cheesy')" }, { group_by => [ qw/tag cd/ ] });
is($rs->count, 7, 'Count with literal SQL and multiple group_by');
+
+my @warnings;
+{
+ local $SIG{__WARN__} = sub { push @warnings, shift };
+ my $row = $schema->resultset('Tag')->search({}, { select => { distinct => 'tag' } })->first;
+}
+
+is(@warnings, 1, 'expecteing warn');
+
+dies_ok(sub { my $row = $schema->resultset('Tag')->search({}, { select => { distinct => [qw/tag cd/] } })->first }, 'expecting to die');