From: Peter Rabbitson Date: Sat, 15 May 2010 16:04:59 +0000 (+0000) Subject: Revert erroneous commit (belongs in a branch) X-Git-Tag: v0.08122~67 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=22912b455e1116d0172ac9dea850304b82c96ac1;p=dbsrgits%2FDBIx-Class.git Revert erroneous commit (belongs in a branch) --- diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index c362e91..40bc7a3 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -485,8 +485,6 @@ sub _recurse_fields { 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.' @@ -577,23 +575,6 @@ sub _order_directions { ]); } -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') { diff --git a/t/bind/order_by.t b/t/bind/order_by.t index 7f8df43..7a8bce6 100644 --- a/t/bind/order_by.t +++ b/t/bind/order_by.t @@ -103,3 +103,4 @@ my @tests = ( plan( tests => scalar @tests * 2 ); test_order($_) for @tests; + diff --git a/t/sqlahacks/order_by_func.t b/t/sqlahacks/order_by_func.t index 1caac14..51968ed 100644 --- a/t/sqlahacks/order_by_func.t +++ b/t/sqlahacks/order_by_func.t @@ -7,45 +7,29 @@ use DBICTest; 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;