X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=blobdiff_plain;f=t%2Fprefetch%2Fo2m_o2m_order_by_with_limit.t;h=1a91e423237c6bb924446b7355293cfdc5f45b34;hp=a4476c302a9dd549ff69bf2ddf04b508185c32cd;hb=908aa1bb761ec1da5c061fe9f687598e3f1934bc;hpb=0e773352a9c6c034dfb2526b8d68bf6ac1e2323b diff --git a/t/prefetch/o2m_o2m_order_by_with_limit.t b/t/prefetch/o2m_o2m_order_by_with_limit.t index a4476c3..1a91e42 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,24 @@ 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 = ? ) - 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 )}, - [ map { [ { sqlt_datatype => 'integer', dbic_colname => 'me.rank' } - => 13 ] } (1,2) + [ + [ { 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', ); @@ -71,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', @@ -87,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' @@ -105,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' @@ -124,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'