X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource.pm;h=3233e3ab4a1b45d8cd0883e6881e5e6666551e35;hb=fe386563d35a0e019c70500e1fd01b3514942eed;hp=3c9bda149e8acefca13ae9a77ab9eee6632688f6;hpb=8228ee62d5c7a22d126cd19aca3894f9675fc40d;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 3c9bda1..3233e3a 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -84,7 +84,7 @@ created, see L for full details. =head2 Finding result source objects As mentioned above, a result source instance is created and stored for -you when you define a L. +you when you define a L. You can retrieve the result source at runtime in the following ways: @@ -96,7 +96,7 @@ You can retrieve the result source at runtime in the following ways: =item From a Result object: - $row->result_source; + $result->result_source; =item From a ResultSet object: @@ -627,7 +627,7 @@ sub primary_columns { # a helper method that will automatically die with a descriptive message if # no pk is defined on the source in question. For internal use to save # on if @pks... boilerplate -sub _pri_cols { +sub _pri_cols_or_die { my $self = shift; my @pcols = $self->primary_columns or $self->throw_exception (sprintf( @@ -638,6 +638,20 @@ sub _pri_cols { return @pcols; } +# same as above but mandating single-column PK (used by relationship condition +# inferrence) +sub _single_pri_col_or_die { + my $self = shift; + my ($pri, @too_many) = $self->_pri_cols_or_die; + + $self->throw_exception( sprintf( + "Operation requires a single-column primary key declared on '%s'", + $self->source_name || $self->result_class || $self->name || 'Unknown source...?', + )) if @too_many; + return $pri; +} + + =head2 sequence Manually define the correct sequence for your table, to avoid the overhead @@ -1433,12 +1447,10 @@ sub reverse_relationship_info { my $stripped_cond = $self->__strip_relcond ($rel_info->{cond}); - my $rsrc_schema_moniker = $self->source_name - if try { $self->schema }; + my $registered_source_name = $self->source_name; # this may be a partial schema or something else equally esoteric - my $other_rsrc = try { $self->related_source($rel) } - or return $ret; + my $other_rsrc = $self->related_source($rel); # Get all the relationships for that source that related to this source # whose foreign column set are our self columns on $rel and whose self @@ -1453,11 +1465,11 @@ sub reverse_relationship_info { my $roundtrip_rsrc = try { $other_rsrc->related_source($other_rel) } or next; - if ($rsrc_schema_moniker and try { $roundtrip_rsrc->schema } ) { - next unless $rsrc_schema_moniker eq $roundtrip_rsrc->source_name; + if ($registered_source_name) { + next if $registered_source_name ne ($roundtrip_rsrc->source_name || '') } else { - next unless $self->result_class eq $roundtrip_rsrc->result_class; + next if $self->result_class ne $roundtrip_rsrc->result_class; } my $other_rel_info = $other_rsrc->relationship_info($other_rel); @@ -1666,12 +1678,12 @@ our $UNRESOLVABLE_CONDITION = \ '1 = 0'; # Resolves the passed condition to a concrete query fragment and a flag # indicating whether this is a cross-table condition. Also an optional -# list of non-triviail values (notmally conditions) returned as a part +# list of non-trivial values (normally conditions) returned as a part # of a joinfree condition hash sub _resolve_condition { my ($self, $cond, $as, $for, $rel_name) = @_; - my $obj_rel = !!blessed $for; + my $obj_rel = defined blessed $for; if (ref $cond eq 'CODE') { my $relalias = $obj_rel ? 'me' : $as;