sub last_insert_id { shift->_identity }
+#
+# MSSQL is retarded wrt ordered subselects. One needs to add a TOP 100%
+# to *all* subqueries, do it here.
+#
+sub _select_args_to_query {
+ my $self = shift;
+
+ my $sql_maker = $self->sql_maker;
+ my ($op, $bind, $ident, $bind_attrs, $select, $cond, $order) = $self->_select_args(@_);
+
+ if (not scalar $sql_maker->_order_by_chunks ($order->{order_by}) ) {
+ # no ordering, just short circuit
+ return $self->next::method (@_);
+ }
+
+ my ($sql, $bind, @rest) = $self->next::method (@_);
+ $sql =~ s/^ \s* SELECT \s/SELECT TOP 100 PERCENT /xi;
+
+ return wantarray
+ ? ($sql, $bind, @rest)
+ : \[ "($sql)", @$bind ]
+ ;
+}
+
+
# savepoint syntax is the same as in Sybase ASE
sub _svp_begin {
]);
}, 'populate without PKs supplied ok' );
+# make sure ordered subselects work
+{
+ my $book_owner_ids = $schema->resultset ('BooksInLibrary')
+ ->search ({}, { join => 'owner', distinct => 1, order_by => { -desc => 'owner'} })
+ ->get_column ('owner');
+
+ my $owners = $schema->resultset ('Owners')->search ({
+ id => { -in => $book_owner_ids->as_query }
+ });
+
+ is ($owners->count, 8, 'Correct amount of book owners');
+ is ($owners->all, 8, 'Correct amount of book owner objects');
+}
+
#
# try a prefetch on tables with identically named columns
#