my $last = pop @el;
my $p = $map;
$p = $p->{$_} ||= {} for @el;
- if (my $alias = $p->{''}{'-alias'}) {
- return Identifier($alias, $last);
+ unless ($p->{''}) {
+ my $need = my $j = {};
+ $j = $j->{$_} = {} for @el;
+ my $rsrc = $map->{''}{-rsrc};
+ $rsrc = $rsrc->related_source($_) for @el;
+ push @need_join, $need;
+ my $alias = $storage->relname_to_table_alias(
+ $el[-1], ++$seen_join->{$el[-1]}
+ );
+ $p->{''} = { -alias => $alias, -rsrc => $rsrc };
}
- my $need = my $j = {};
- $j = $j->{$_} = {} for @el;
- push @need_join, $need;
- my $alias = $storage->relname_to_table_alias(
- $el[-1], ++$seen_join->{$el[-1]}
- );
- return Identifier($alias, $last);
+ my $info = $p->{''};
+ my $col_map = $info->{-column_mapping} ||= do {
+ my $colinfo = $info->{-rsrc}->columns_info;
+ +{ map +(($colinfo->{$_}{rename_for_dq}||$_) => $_), keys %$colinfo }
+ };
+ die "Invalid name on ".(join(',',@el)||'me').": $last"
+ unless $col_map->{$last};
+ return Identifier($info->{-alias}, $col_map->{$last});
} $dq;
return ($mapped, \@need_join);
}
my $cds = $schema->resultset('CD');
+throws_ok {
+ $cds->_remap_identifiers(Identifier('name'))
+} qr/Invalid name on me: name/;
+
is_deeply(
- [ $cds->_remap_identifiers(Identifier('name')) ],
- [ Identifier('me', 'name'), [] ],
+ [ $cds->_remap_identifiers(Identifier('title')) ],
+ [ Identifier('me', 'title'), [] ],
'Remap column on me'
);
'Remap column on rel with re-alias'
);
+is_deeply(
+ [ $cds->_remap_identifiers(Identifier('artist_id')) ],
+ [ Identifier('me', 'artist'), [] ],
+ 'Remap column w/column name rename'
+);
+
+my $double_name = expr { $_->artist->name == $_->artist->name }->{expr};
+
+is_deeply(
+ [ $cds->_remap_identifiers($double_name) ],
+ [ $double_name, [ { artist => {} } ] ],
+ 'Remap column on rel only adds rel once'
+);
+
done_testing;