From: Peter Rabbitson Date: Mon, 17 Jan 2011 02:49:54 +0000 (+0100) Subject: Pass relationship name to _resolve_condition explicitly X-Git-Tag: v0.08190~1^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=1605376709663b035385b41828ce13ae3ed45a4d Pass relationship name to _resolve_condition explicitly The API is ambuguous at best, will need a cleanup some day, for now just do by tackling even more arguments to the method, yielding insanity like: _resolve_condition($cond, $obj, $f_rel, $f_rel) BLEH! --- diff --git a/lib/DBIx/Class/Relationship/Accessor.pm b/lib/DBIx/Class/Relationship/Accessor.pm index 03700f4..1c73950 100644 --- a/lib/DBIx/Class/Relationship/Accessor.pm +++ b/lib/DBIx/Class/Relationship/Accessor.pm @@ -32,7 +32,7 @@ sub add_relationship_accessor { return $self->{_relationship_data}{$rel}; } else { my $cond = $self->result_source->_resolve_condition( - $rel_info->{cond}, $rel, $self + $rel_info->{cond}, $rel, $self, $rel ); if ($rel_info->{attrs}->{undef_on_null_fk}){ return undef unless ref($cond) eq 'HASH'; diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 41a8fec..a6af9db 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -424,7 +424,7 @@ sub related_resultset { # additional condition in order to avoid an unecessary join if # that is at all possible. my ($cond, $extended_cond) = try { - $source->_resolve_condition( $rel_info->{cond}, $rel, $self ) + $source->_resolve_condition( $rel_info->{cond}, $rel, $self, $rel ) } catch { if ($self->in_storage) { @@ -714,7 +714,7 @@ sub set_from_related { # _resolve_condition might return two hashrefs, specially in the # current case, since we know $f_object is an object. my ($condref1, $condref2) = $self->result_source->_resolve_condition - ($rel_info->{cond}, $f_obj, $rel); + ($rel_info->{cond}, $f_obj, $rel, $rel); # if we get two condrefs, we need to use the second, otherwise we # use the first. diff --git a/lib/DBIx/Class/Relationship/ManyToMany.pm b/lib/DBIx/Class/Relationship/ManyToMany.pm index c588419..675f206 100644 --- a/lib/DBIx/Class/Relationship/ManyToMany.pm +++ b/lib/DBIx/Class/Relationship/ManyToMany.pm @@ -136,7 +136,7 @@ EOW my $link_cond; if (ref $cond eq 'CODE') { my ($cond_should_join, $cond_optimized) = $rel_source->_resolve_condition - ($cond, $obj, $f_rel); + ($cond, $obj, $f_rel, $f_rel); if ($cond_optimized) { $link_cond = $cond_optimized; } else { diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index a12095f..5e4b8b5 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -697,7 +697,7 @@ sub find { next if $keyref eq 'ARRAY'; # has_many for multi_create my $rel_q = $rsrc->_resolve_condition( - $relinfo->{cond}, $val, $key + $relinfo->{cond}, $val, $key, $key ); die "Can't handle complex relationship conditions in find" if ref($rel_q) ne 'HASH'; @related{keys %$rel_q} = values %$rel_q; @@ -1974,6 +1974,7 @@ sub populate { $reverse_relinfo->{cond}, $self, $result, + $rel, ); delete $data->[$index]->{$rel}; @@ -2012,6 +2013,7 @@ sub populate { $rels->{$rel}{cond}, $child, $main_row, + $rel, ); my @rows_to_add = ref $item->{$rel} eq 'ARRAY' ? @{$item->{$rel}} : ($item->{$rel}); diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 71653e0..d596d2a 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -1493,7 +1493,8 @@ sub _resolve_join { -alias => $as, -relation_chain_depth => $seen->{-relation_chain_depth} || 0, }, - $self->_resolve_condition($rel_info->{cond}, $as, $alias, $join) ]; + $self->_resolve_condition($rel_info->{cond}, $as, $alias, $join) + ]; } } @@ -1551,7 +1552,7 @@ sub resolve_condition { our $UNRESOLVABLE_CONDITION = \ '1 = 0'; sub _resolve_condition { - my ($self, $cond, $as, $for, $rel) = @_; + my ($self, $cond, $as, $for, $relname) = @_; if (ref $cond eq 'CODE') { my $obj_rel = !!ref $for; @@ -1560,7 +1561,7 @@ sub _resolve_condition { self_alias => $obj_rel ? $as : $for, foreign_alias => $obj_rel ? 'me' : $as, self_resultsource => $self, - foreign_relname => $rel || ($obj_rel ? $as : $for), + foreign_relname => $relname || ($obj_rel ? $as : $for), self_rowobj => $obj_rel ? $for : undef }); @@ -1606,7 +1607,7 @@ sub _resolve_condition { } return \%ret; } elsif (ref $cond eq 'ARRAY') { - return [ map { $self->_resolve_condition($_, $as, $for) } @$cond ]; + return [ map { $self->_resolve_condition($_, $as, $for, $relname) } @$cond ]; } else { $self->throw_exception ("Can't handle condition $cond yet :("); } diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 380f1db..f459dc8 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -1062,7 +1062,7 @@ sub copy { next unless $rel_info->{attrs}{cascade_copy}; my $resolved = $self->result_source->_resolve_condition( - $rel_info->{cond}, $rel, $new + $rel_info->{cond}, $rel, $new, $rel ); my $copied = $rels_copied->{ $rel_info->{source} } ||= {};