croak "Malformed select argument - too many keys in hash: " . join (',', keys %$fields );
}
- $func =~ s/^\-+//; # strip leading dash, at some point the dash itself should become mandatory
-
if (lc ($func) eq 'distinct' && ref $args eq 'ARRAY' && @$args > 1) {
croak (
'The select => { distinct => ... } syntax is not supported for multiple columns.'
]);
}
-sub _order_by_chunks {
- my ($self, $arg) = @_;
- if ( # non-empty hash with neither an -asc or a -desc
- ref $arg eq 'HASH'
- &&
- keys %$arg
- &&
- ! exists $arg->{-desc}
- &&
- ! exists $arg->{-asc}
- ) {
- return $self->_recurse_fields ($arg);
- }
-
- return $self->SUPER::_order_by_chunks ($arg);
-}
-
sub _table {
my ($self, $from) = @_;
if (ref $from eq 'ARRAY') {
use DBIC::SqlMakerTest;
my $schema = DBICTest->init_schema();
-$schema->storage->sql_maker->quote_char ('"');
-$schema->storage->sql_maker->name_sep ('.');
my $rs = $schema->resultset('CD')->search({}, {
'join' => 'tracks',
- order_by => [
- { -length => 'me.title' },
- {
+ order_by => {
-desc => {
- count => 'tracks.trackid',
+ count => 'tracks.track_id',
},
- },
- ],
+ },
distinct => 1,
rows => 2,
- page => 2,
+ page => 1,
});
+my $match = q{
+ SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me
+ GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
+ ORDER BY COUNT(tracks.trackid) DESC
+};
-is_same_sql_bind(
- $rs->as_query,
- '(
- SELECT "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track"
- FROM cd "me"
- LEFT JOIN "track" "tracks" ON "tracks"."cd" = "me"."cdid"
- GROUP BY "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track"
- ORDER BY
- LENGTH( "me"."title" ),
- COUNT( "tracks"."trackid" ) DESC
- LIMIT 2 OFFSET 2
- )',
- [],
- 'order by with func query',
-);
+TODO: {
+ todo_skip 'order_by using function', 2;
+ is_same_sql($rs->as_query, $match, 'order by with func query');
-ok($rs->count_rs->next == 2, 'amount of rows return in order by func query');
-is_deeply (
- [ $rs->get_column ('me.title')->all ],
- [ "Caterwaulin' Blues", "Come Be Depressed With Us" ],
- 'Correctly ordered stuff by title-length',
-);
+ ok($rs->count == 2, 'amount of rows return in order by func query');
+}
done_testing;