my $cols;
for my $col ($self->unique_constraint_columns($args->{constraint_name}) ) {
- if( ! exists $vals->{$col} ) {
- $cols->{missing}{$col} = 1;
+ if( ! exists $vals->{$col} or ( $vals->{$col}||'' ) eq UNRESOLVABLE_CONDITION ) {
+ $cols->{missing}{$col} = undef;
}
elsif( ! defined $vals->{$col} ) {
- $cols->{$args->{carp_on_nulls} ? 'undefined' : 'missing'}{$col} = 1;
+ $cols->{$args->{carp_on_nulls} ? 'undefined' : 'missing'}{$col} = undef;
}
else {
- $cols->{present}{$col} = 1;
+ # we need to inject back the '=' as _extract_fixed_condition_columns
+ # will strip it from literals and values alike, resulting in an invalid
+ # condition in the end
+ $cols->{present}{$col} = { '=' => $vals->{$col} };
}
$cols->{fc}{$col} = 1 if (
- ! ( $cols->{missing} || {})->{$col}
+ ( ! $cols->{missing} or ! exists $cols->{missing}{$col} )
and
keys %{ $args->{columns_info}{$col}{_filter_info} || {} }
);
));
}
- return { map
- { $_ => $vals->{$_} }
- ( keys %{$cols->{present}}, keys %{$cols->{undefined}} )
- };
+ return { map { %{ $cols->{$_}||{} } } qw(present undefined) };
}
# Returns the {from} structure used to express JOIN conditions
is($schema->resultset("Artist")->count, 4, 'count ok');
+# test find on an unresolvable condition
+is(
+ $schema->resultset('Artist')->find({ artistid => [ -and => 1, 2 ]}),
+ undef
+);
+
+
# test find_or_new
{
my $existing_obj = $schema->resultset('Artist')->find_or_new({
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+my $rs = $schema->resultset('Artist');
+
+for my $id (
+ 2,
+ \' = 2 ',
+ \[ '= ?', 2 ],
+) {
+ lives_ok {
+ is( $rs->find({ artistid => $id })->id, 2 )
+ } "Correctly found artist with id of @{[ explain $id ]}";
+}
+
+for my $id (
+ 2,
+ \'2',
+ \[ '?', 2 ],
+) {
+ my $cond = { artistid => { '=', $id } };
+ lives_ok {
+ is( $rs->find($cond)->id, 2 )
+ } "Correctly found artist with id of @{[ explain $cond ]}";
+}
+
+done_testing;