X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource.pm;h=24018f3f696aa94f50788546a1b84e6e12e823f8;hb=0a4b8fe0bec137ad4158b5e984cdd38c3e02a50a;hp=f3c4b4f52187759d54fdd51381a2fbe08f836095;hpb=4678e9dae8607c8ca38257c1ddd5d850ebb28dda;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index f3c4b4f..24018f3 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -6,7 +6,6 @@ use warnings; use DBIx::Class::ResultSet; use DBIx::Class::ResultSourceHandle; use Carp::Clan qw/^DBIx::Class/; -use Storable; use base qw/DBIx::Class/; @@ -1237,9 +1236,10 @@ sub _resolve_join { my $type; if ($force_left) { $type = 'left'; - } else { - $type = $rel_info->{attrs}{join_type} || ''; - $force_left = 1 if lc($type) eq 'left'; + } + else { + $type = $rel_info->{attrs}{join_type}; + $force_left = 1 if lc($type||'') eq 'left'; } my $rel_src = $self->related_source($join); @@ -1265,18 +1265,22 @@ sub pk_depends_on { # hashref of columns of the related object. sub _pk_depends_on { my ($self, $relname, $rel_data) = @_; - my $cond = $self->relationship_info($relname)->{cond}; + my $relinfo = $self->relationship_info($relname); + + # don't assume things if the relationship direction is specified + return $relinfo->{attrs}{is_foreign_key_constraint} + if exists ($relinfo->{attrs}{is_foreign_key_constraint}); + + my $cond = $relinfo->{cond}; return 0 unless ref($cond) eq 'HASH'; # map { foreign.foo => 'self.bar' } to { bar => 'foo' } - my $keyhash = { map { my $x = $_; $x =~ s/.*\.//; $x; } reverse %$cond }; # assume anything that references our PK probably is dependent on us # rather than vice versa, unless the far side is (a) defined or (b) # auto-increment - my $rel_source = $self->related_source($relname); foreach my $p ($self->primary_columns) { @@ -1318,10 +1322,14 @@ sub _resolve_condition { #warn "$self $k $for $v"; unless ($for->has_column_loaded($v)) { if ($for->in_storage) { - $self->throw_exception( - "Column ${v} not loaded or not passed to new() prior to insert()" - ." on ${for} trying to resolve relationship (maybe you forgot " - ."to call ->discard_changes to get defaults from the db)" + $self->throw_exception(sprintf + 'Unable to resolve relationship from %s to %s: column %s.%s not ' + . 'loaded from storage (or not passed to new() prior to insert()). ' + . 'Maybe you forgot to call ->discard_changes to get defaults from the db.', + + $for->result_source->source_name, + $as, + $as, $v, ); } return $UNRESOLVABLE_CONDITION; @@ -1454,7 +1462,7 @@ sub _resolve_prefetch { $p = $p->{$_} for (@$pref_path, $pre); $self->throw_exception ( - "Unable to resolve prefetch $pre - join alias map does not contain an entry for path: " + "Unable to resolve prefetch '$pre' - join alias map does not contain an entry for path: " . join (' -> ', @$pref_path, $pre) ) if (ref $p->{-join_aliases} ne 'ARRAY' or not @{$p->{-join_aliases}} );