artist_id => $inside_rs->get_column('id')->as_query,
});
+=head3 Support
+
+Subqueries are supported in the where clause (first hashref), and in the
+from, select, and +select attributes.
+
=head3 Correlated subqueries
my $cdrs = $schema->resultset('CD');
WHERE artistid = me.artistid
)
-=head2 Where subqueries will work
-
-Currently, subqueries will B<only> work in the where-clause of a search. In
-other words, in the first hashref of a search() method. Work is being done
-to make them work as part of the second hashref (from, select, +select, etc).
-
=head2 Predefined searches
You can write your own L<DBIx::Class::ResultSet> class by inheriting from it
.'( '.$self->_recurse_fields($fields->{$func}).' )';
}
}
+ # Is the second check absolutely necessary?
+ elsif ( $ref eq 'REF' and ref($$fields) eq 'ARRAY' ) {
+ return $self->_bind_to_sql( $fields );
+ }
+ else {
+ Carp::croak($ref . qq{ unexpected in _recurse_fields()})
+ }
}
sub _order_by {
$attrs->{rows} = 2**48 if not defined $attrs->{rows} and defined $attrs->{offset};
push @args, $attrs->{rows}, $attrs->{offset};
}
-
return @args;
}
eval "use SQL::Abstract 1.49";
plan $@
? ( skip_all => "Needs SQLA 1.49+" )
- : ( tests => 6 );
+ : ( tests => 7 );
}
use lib qw(t/lib);
);
}
-TODO: {
- local $TODO = "'+select' doesn't work with as_query yet.";
+{
my $rs = $art_rs->search(
{},
{
- '+select' => [
+ 'select' => [
$cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
],
- '+as' => [
- 'cdid',
+ },
+ );
+
+ my $arr = $rs->as_query;
+ my ($query, @bind) = @{$$arr};
+ is_same_sql_bind(
+ $query, \@bind,
+ "SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me",
+ [],
+ );
+}
+
+{
+ my $rs = $art_rs->search(
+ {},
+ {
+ '+select' => [
+ $cdrs->search({}, { rows => 1 })->get_column('id')->as_query,
],
},
);
my ($query, @bind) = @{$$arr};
is_same_sql_bind(
$query, \@bind,
- "SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cds LIMIT 1) AS cdid FROM artist me",
+ "SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me",
[],
);
}