use DBIx::Class::ResultSetColumn;
use DBIx::Class::ResultClass::HashRefInflator;
use Scalar::Util qw( blessed reftype );
+use SQL::Abstract 'is_literal_value';
use DBIx::Class::_Util qw(
dbic_internal_try dbic_internal_catch dump_value emit_loud_diag
fail_on_internal_wantarray fail_on_internal_call UNRESOLVABLE_CONDITION
my $self = shift;
my $attrs = (@_ > 1 && ref $_[-1] eq 'HASH' ? pop(@_) : {});
- my $rsrc = $self->result_source;
my $constraint_name;
if (exists $attrs->{key}) {
# Parse out the condition from input
my $call_cond;
+ my $rsrc = $self->result_source;
+
if (ref $_[0] eq 'HASH') {
$call_cond = { %{$_[0]} };
}
}
# process relationship data if any
+ my $rel_list;
+
for my $key (keys %$call_cond) {
if (
length ref($call_cond->{$key})
and
- my $relinfo = $rsrc->relationship_info($key)
+ ( $rel_list ||= { map { $_ => 1 } $rsrc->relationships } )
+ ->{$key}
and
- # implicitly skip has_many's (likely MC)
+ ! is_literal_value( $call_cond->{$key} )
+ and
+ # implicitly skip has_many's (likely MC), via the delete()
( ref( my $val = delete $call_cond->{$key} ) ne 'ARRAY' )
) {
- my ($rel_cond, $crosstable) = $rsrc->_resolve_condition(
- $relinfo->{cond}, $val, $key, $key
- );
- $self->throw_exception("Complex condition via relationship '$key' is unsupported in find()")
- if $crosstable or ref($rel_cond) ne 'HASH';
+ # FIXME: it seems wrong that relationship conditions take precedence...?
+ $call_cond = {
+ %$call_cond,
- # supplement condition
- # relationship conditions take precedence (?)
- @{$call_cond}{keys %$rel_cond} = values %$rel_cond;
+ %{ $rsrc->_resolve_relationship_condition(
+ rel_name => $key,
+ foreign_values => $val,
+ infer_values_based_on => {},
+
+ self_alias => "\xFE", # irrelevant
+ foreign_alias => "\xFF", # irrelevant
+ )->{inferred_values} },
+ };
}
}
my $schema = DBICTest->init_schema();
+$schema->is_executed_sql_bind(
+ sub { $schema->resultset('Artist')->find( Math::BigInt->new(42) ) },
+ [
+ [
+ 'SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE me.artistid = ?',
+ [ { dbic_colname => "me.artistid", sqlt_datatype => "integer" }
+ => Math::BigInt->new(42) ],
+ ]
+ ]
+);
+
my $rs = $schema->resultset('CD')->search({ -and => [
'me.artist' => { '!=', '666' },
'me.artist' => { '!=', \[ '?', [ _ne => 'bar' ] ] },
--- /dev/null
+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+
+use DBICTest;
+
+my $schema = DBICTest->init_schema( no_deploy => 1 );
+
+my $artist = $schema->resultset('Artist')->new_result({ artistid => 1 });
+
+throws_ok {
+ $schema->resultset('ArtistUndirectedMap')->find({
+ mapped_artists => $artist,
+ });
+} qr/\QUnable to complete value inferrence - relationship 'mapped_artists' on source 'ArtistUndirectedMap' results in expression(s) instead of definitive values: ( id1 = ? OR id2 = ? )/,
+ 'proper exception on OR relationship inferrence'
+;
+
+throws_ok {
+ $schema->resultset('Artwork_to_Artist')->find({
+ artist_limited_rank_opaque => $artist
+ })
+} qr/\QRelationship 'artist_limited_rank_opaque' on source 'Artwork_to_Artist' does not resolve to a 'foreign_values'-based reversed-join-free condition fragment/,
+ 'proper exception on ipaque custom cond'
+;
+
+done_testing;