my $schema = DBICTest->init_schema;
# Trick the sqlite DB to use Top limit emulation
+# We could test all of this via $sq->$op directly,
+# but some conditions needs a $rsrc
delete $schema->storage->_sql_maker->{_cached_syntax};
$schema->storage->_sql_maker->limit_dialect ('Top');
-my $rs = $schema->resultset ('FourKeys')->search ({}, { rows => 1, offset => 3 });
+my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { prefetch => 'owner', rows => 1, offset => 3 });
sub test_order {
my $args = shift;
) bar
$req_order
)",
- [],
+ [ [ source => 'Library' ] ],
);
}
},
);
-plan (tests => scalar @tests);
+plan (tests => scalar @tests + 1);
+
test_order ($_) for @tests;
+
+is_same_sql_bind (
+ $rs->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
+ '(
+ SELECT me__id, source, owner, title, price, owner__id, name
+ FROM (
+ SELECT TOP 1 me__id, source, owner, title, price, owner__id, name
+ FROM (
+ SELECT TOP 4 me.id AS me__id, me.source, me.owner, me.title, me.price, owner.id AS owner__id, owner.name
+ FROM books me
+ JOIN owners owner ON owner.id = me.owner
+ WHERE ( source = ? )
+ GROUP BY title
+ ORDER BY title ASC
+ ) AS me
+ ORDER BY title DESC
+ ) AS me
+ ORDER BY title;
+ )',
+ [ [ source => 'Library' ] ],
+);