return $cond unless ref $full_cond;
foreach my $pk ($self->result_source->primary_columns) {
- $cond->{$pk} = { IN => $self->get_column($pk)->as_query({ skip_parens => 1 }) };
+ $cond->{$pk} = { -in => $self->get_column($pk)->as_query };
}
return $cond;
=over 4
-=item Arguments: \%opts
+=item Arguments: none
=item Return Value: \[ $sql, @bind ]
B<NOTE>: This feature is still experimental.
-The query returned will be surrounded by parentheses, e.g:
-
- ( SELECT cdid FROM cd WHERE title LIKE '%Hits%' )
-
-This behaviour can be changed by passing special options:
-
- $rs->get_column('cdid')->as_query({ skip_parens => 1 });
-
=cut
sub as_query { return shift->cursor->as_query(@_) }
=over 4
-=item Arguments: See L<DBIx::Class::ResultSet/as_query>
+=item Arguments: none
=item Return Value: \[ $sql, @bind ]
=over 4
-=item Arguments: See L<DBIx::Class::ResultSet/as_query>
+=item Arguments: none
=item Return Value: \[ $sql, @bind ]
=cut
sub as_query {
- my ( $self, $opts ) = @_;
-
- $self->throw_exception( "as_query needs a hashref" )
- if defined $opts and ref $opts ne 'HASH';
-
- $opts->{skip_parens} ||= 0;
+ my $self = shift;
my $storage = $self->{storage};
my $sql_maker = $storage->sql_maker;
my @args = $storage->_select_args(@{$self->{args}});
my ($sql, $bind) = $storage->_prep_for_execute(@args[0 .. 2], [@args[4 .. $#args]]);
- $sql = "($sql)" unless $opts->{skip_parens};
- return \[ $sql, @$bind ];
+ return \[ "($sql)", @$bind ];
}
=head2 next
use Test::More;
-plan ( tests => 6 );
+plan ( tests => 4 );
use lib qw(t/lib);
use DBICTest;
[ [ rank => 2 ], [ name => 'Billy Joel' ] ],
);
}
-
-{
- my $rs = $schema->resultset("CD")->search(
- { 'artist.name' => 'Caterwauler McCrae' },
- { join => [qw/artist/]}
- );
- my $query = $rs->get_column('cdid')->as_query({ skip_parens => 1 });
- my ($sql, @bind) = @{$$query};
- is_same_sql_bind(
- $sql, \@bind,
- 'SELECT me.cdid FROM cd me JOIN artist artist ON artist.artistid = me.artist WHERE ( artist.name = ? )',
- [['artist.name' => 'Caterwauler McCrae']]
- );
- my $subsel_rs = $schema->resultset("CD")->search( { cdid => { IN => $query } } );
- is($subsel_rs->count, $rs->count, 'Subselect on PK got the same row count');
-}
-
-__END__