);
if (ref($related) eq 'REF' and ref($$related) eq 'HASH') {
- $related = $self->_extract_fixed_values_for($$related, $rel);
+ $related = $self->result_source
+ ->_extract_fixed_values_for($$related, $rel);
}
my @rows_to_add = ref $item->{$rel} eq 'ARRAY' ? @{$item->{$rel}} : ($item->{$rel});
}
}
-sub _extract_fixed_values_for {
- my ($self, $dq, $alias) = @_;
- my $fixed = $self->_extract_fixed_conditions_for($dq, $alias);
- return +{ map {
- is_Value($fixed->{$_})
- ? ($_ => $fixed->{$_}{value})
- : ()
- } keys %$fixed };
-}
-
-sub _extract_fixed_conditions_for {
- my ($self, $dq, $alias) = @_;
- my (@q, %found) = ($dq);
- while (my $n = shift @q) {
- if (is_Operator($n)) {
- if (($n->{operator}{Perl}||'') =~ /^(?:==|eq)$/) {
- my ($l, $r) = @{$n->{args}};
- if (
- is_Identifier($r) and @{$r->{elements}} == 2
- and $r->{elements}[0] eq $alias
- ) {
- ($l, $r) = ($r, $l);
- }
- if (
- is_Identifier($l) and @{$l->{elements}} == 2
- and $l->{elements}[0] eq $alias
- ) {
- $found{$l->{elements}[1]} = $r;
- } elsif (($n->{operator}{Perl}||'') eq 'and') {
- push @q, @{$n->{args}};
- }
- }
- }
- }
- return \%found;
-}
-
# populate() arguments went over several incarnations
# What we ultimately support is AoH
sub _normalize_populate_args {
}
}
elsif (ref $self->{cond} eq 'REF' and ref ${$self->{cond}} eq 'HASH') {
- %new_data = %{$self->_extract_fixed_values_for(${$self->{cond}}, $alias)};
+ %new_data = %{$self->result_source
+ ->_extract_fixed_values_for(${$self->{cond}}, $alias)};
}
else {
$self->throw_exception(
return undef;
}
+sub _extract_fixed_values_for {
+ my ($self, $dq, $alias) = @_;
+ my $fixed = $self->_extract_fixed_conditions_for($dq, $alias);
+ return +{ map {
+ is_Value($fixed->{$_})
+ ? ($_ => $fixed->{$_}{value})
+ : ()
+ } keys %$fixed };
+}
+
+sub _extract_fixed_conditions_for {
+ my ($self, $dq, $alias) = @_;
+ my (@q, %found) = ($dq);
+ while (my $n = shift @q) {
+ if (is_Operator($n)) {
+ if (($n->{operator}{Perl}||'') =~ /^(?:==|eq)$/) {
+ my ($l, $r) = @{$n->{args}};
+ if (
+ is_Identifier($r) and @{$r->{elements}} == 2
+ and $r->{elements}[0] eq $alias
+ ) {
+ ($l, $r) = ($r, $l);
+ }
+ if (
+ is_Identifier($l) and @{$l->{elements}} == 2
+ and $l->{elements}[0] eq $alias
+ ) {
+ $found{$l->{elements}[1]} = $r;
+ } elsif (($n->{operator}{Perl}||'') eq 'and') {
+ push @q, @{$n->{args}};
+ }
+ }
+ }
+ }
+ return \%found;
+}
+
sub compare_relationship_keys {
carp 'compare_relationship_keys is a private method, stop calling it';
my $self = shift;
my $new = { _column_data => $col_data };
bless $new, ref $self;
- $new->result_source($self->result_source);
+ $new->result_source(my $source = $self->result_source);
$new->set_inflated_columns($changes);
$new->insert;
# constraints
my $relnames_copied = {};
- foreach my $relname ($self->result_source->relationships) {
- my $rel_info = $self->result_source->relationship_info($relname);
+ foreach my $relname ($source->relationships) {
+ my $rel_info = $source->relationship_info($relname);
next unless $rel_info->{attrs}{cascade_copy};
- my $resolved = $self->result_source->_resolve_condition(
+ my $resolved = $source->_resolve_condition(
$rel_info->{cond}, $relname, $new, $relname
);
+ if (ref($resolved) eq 'REF') {
+ $resolved = $source->_extract_fixed_values_for($$resolved, 'me');
+ }
+
my $copied = $relnames_copied->{ $rel_info->{source} } ||= {};
foreach my $related ($self->search_related($relname)->all) {
my $id_str = join("\0", $related->id);