mode of a has_many prefetch off a search_related chain
- Prevent erroneous database hit when accessing prefetched related
resultsets with no rows
+ - Proper exceptions on malformed relationship conditions (RT#92234)
- Fix incorrect handling of custom relationship conditions returning
SQLA literal expressions
- Fix long standing bug with populate() missing data from hashrefs with
else {
if (ref $cond eq 'HASH') { # ARRAY is also valid
my $cond_rel;
+ # FIXME This loop is ridiculously incomplete and dangerous
+ # staving off changes until implmentation of the swindon consensus
for (keys %$cond) {
if (m/\./) { # Explicit join condition
$cond_rel = $cond;
my $self_id = $cond->{$foreign_id};
# we can ignore a bad $self_id because add_relationship handles this
- # warning
+ # exception
return unless $self_id =~ /^self\.(.*)$/;
+
my $key = $1;
$class->throw_exception("Defining rel on ${class} that includes '$key' but no such column defined here yet")
unless $class->has_column($key);
# Check foreign and self are right in cond
if ( (ref $cond ||'') eq 'HASH') {
- for (keys %$cond) {
- $self->throw_exception("Keys of condition should be of form 'foreign.col', not '$_'")
- if /\./ && !/^foreign\./;
- }
+ $_ =~ /^foreign\./ or $self->throw_exception("Malformed relationship condition key '$_': must be prefixed with 'foreign.'")
+ for keys %$cond;
+
+ $_ =~ /^self\./ or $self->throw_exception("Malformed relationship condition value '$_': must be prefixed with 'self.'")
+ for values %$cond;
}
my %rels = %{ $self->_relationships };
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest::Schema::Artist;
+
+my $pkg = 'DBICTest::Schema::Artist';
+
+for my $call (qw(has_many might_have has_one belongs_to)) {
+ {
+ local $TODO = 'stupid stupid heuristic - needs to die'
+ if $call eq 'belongs_to';
+
+ throws_ok {
+ $pkg->$call( foos => 'nonexistent bars', { foo => 'self.artistid' } );
+ } qr/Malformed relationship condition key 'foo': must be prefixed with 'foreign.'/,
+ "Correct exception on $call with malformed foreign.";
+ }
+
+ throws_ok {
+ $pkg->has_many( foos => 'nonexistent bars', { 'foreign.foo' => 'name' } );
+ } qr/\QMalformed relationship condition value 'name': must be prefixed with 'self.'/,
+ "Correct exception on $call with malformed self.";
+}
+
+done_testing;