X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fprefetch%2Fo2m_o2m_order_by_with_limit.t;h=f7f71e5d60d28fa1366cbddeb5001631f958b36d;hb=459669a408682896779b908bc29d6264af8702e3;hp=c77530afef75a61e772a16aeca4b81b9189442f2;hpb=3d98c75e2c45cbd5ddd995cbeb48810f6ad7e1ca;p=dbsrgits%2FDBIx-Class.git diff --git a/t/prefetch/o2m_o2m_order_by_with_limit.t b/t/prefetch/o2m_o2m_order_by_with_limit.t index c77530a..f7f71e5 100644 --- a/t/prefetch/o2m_o2m_order_by_with_limit.t +++ b/t/prefetch/o2m_o2m_order_by_with_limit.t @@ -6,6 +6,12 @@ use Test::More; use lib qw(t/lib); use DBIC::SqlMakerTest; use DBICTest; +use DBIx::Class::SQLMaker::LimitDialects; + +my ($ROWS, $OFFSET) = ( + DBIx::Class::SQLMaker::LimitDialects->__rows_bindtype, + DBIx::Class::SQLMaker::LimitDialects->__offset_bindtype, +); my $schema = DBICTest->init_schema(); @@ -16,8 +22,8 @@ my $filtered_cd_rs = $artist_rs->search_related('cds_unordered', { "$ar.rank" => 13 }, { prefetch => [ 'tracks' ], - order_by => [ { -asc => "$ar.name" }, "$ar.artistid DESC" ], - offset => 3, + order_by => [ 'tracks.position DESC', { -asc => "$ar.name" }, "$ar.artistid DESC" ], + offset => 13, rows => 3, }, ); @@ -33,19 +39,25 @@ is_same_sql_bind( FROM artist me JOIN cd cds_unordered ON cds_unordered.artist = me.artistid + LEFT JOIN track tracks + ON tracks.cd = cds_unordered.cdid WHERE ( me.rank = ? ) - GROUP BY cds_unordered.cdid, cds_unordered.artist, cds_unordered.title, cds_unordered.year, cds_unordered.genreid, cds_unordered.single_track, me.name, me.artistid - ORDER BY me.name ASC, me.artistid DESC - LIMIT 3 - OFFSET 3 + ORDER BY tracks.position DESC, me.name ASC, me.artistid DESC + LIMIT ? + OFFSET ? ) cds_unordered ON cds_unordered.artist = me.artistid LEFT JOIN track tracks ON tracks.cd = cds_unordered.cdid WHERE ( me.rank = ? ) - ORDER BY me.name ASC, me.artistid DESC, tracks.cd + ORDER BY tracks.position DESC, me.name ASC, me.artistid DESC )}, - [ [ 'me.rank' => 13 ], [ 'me.rank' => 13 ] ], + [ + [ { sqlt_datatype => 'integer', dbic_colname => 'me.rank' } => 13 ], + [ $ROWS => 3 ], + [ $OFFSET => 13 ], + [ { sqlt_datatype => 'integer', dbic_colname => 'me.rank' } => 13 ], + ], 'correct SQL on limited prefetch over search_related ordered by root', ); @@ -57,7 +69,7 @@ is_same_sql_bind( # cds belong to the second and third artist, respectively, and there's no sixth # row is_deeply ( - [ $filtered_cd_rs->hri_dump ], + $filtered_cd_rs->all_hri, [ { 'artist' => '2', @@ -70,9 +82,9 @@ is_deeply ( 'cd' => '4', 'last_updated_at' => undef, 'last_updated_on' => undef, - 'position' => '1', - 'title' => 'Boring Name', - 'trackid' => '10' + 'position' => '3', + 'title' => 'No More Ideas', + 'trackid' => '12' }, { 'cd' => '4', @@ -86,9 +98,9 @@ is_deeply ( 'cd' => '4', 'last_updated_at' => undef, 'last_updated_on' => undef, - 'position' => '3', - 'title' => 'No More Ideas', - 'trackid' => '12' + 'position' => '1', + 'title' => 'Boring Name', + 'trackid' => '10' } ], 'year' => '2001' @@ -104,14 +116,6 @@ is_deeply ( 'cd' => '5', 'last_updated_at' => undef, 'last_updated_on' => undef, - 'position' => '1', - 'title' => 'Sad', - 'trackid' => '13' - }, - { - 'cd' => '5', - 'last_updated_at' => undef, - 'last_updated_on' => undef, 'position' => '3', 'title' => 'Suicidal', 'trackid' => '15' @@ -123,6 +127,14 @@ is_deeply ( 'position' => '2', 'title' => 'Under The Weather', 'trackid' => '14' + }, + { + 'cd' => '5', + 'last_updated_at' => undef, + 'last_updated_on' => undef, + 'position' => '1', + 'title' => 'Sad', + 'trackid' => '13' } ], 'year' => '1998'