sub _remap_identifiers {
my ($self, $dq) = @_;
- my $map = {};
+ my $map = {
+ '' => {
+ -alias => $self->current_source_alias,
+ -rsrc => $self->result_source,
+ }
+ };
my $attrs = $self->_resolved_attrs;
foreach my $j ( @{$attrs->{from}}[1 .. $#{$attrs->{from}} ] ) {
next unless $j->[0]{-alias};
next unless $j->[0]{-join_path};
my $p = $map;
$p = $p->{$_} ||= {} for map { keys %$_ } @{$j->[0]{-join_path}};
- $p->{''} = $j->[0]{-alias};
+ $p->{''} = $j->[0];
}
my $seen_join = { %{$attrs->{seen_join}||{}} };
return $_ unless is_Identifier;
my @el = @{$_->{elements}};
my $last = pop @el;
- unless (@el) {
- return Identifier($attrs->{alias}, $last);
- }
my $p = $map;
$p = $p->{$_} ||= {} for @el;
- if (my $alias = $p->{''}) {
+ if (my $alias = $p->{''}{'-alias'}) {
return Identifier($alias, $last);
}
my $need = my $j = {};
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use Test::Warn;
+use lib qw(t/lib);
+use Data::Query::ExprDeclare;
+use Data::Query::ExprHelpers;
+use DBICTest;
+use DBIC::SqlMakerTest;
+
+my $schema = DBICTest->init_schema();
+
+$schema->source($_)->resultset_class('DBIx::Class::ResultSet::WithDQMethods')
+ for qw(CD Tag);
+
+my $cds = $schema->resultset('CD');
+
+is_deeply(
+ [ $cds->_remap_identifiers(Identifier('name')) ],
+ [ Identifier('me', 'name'), [] ],
+ 'Remap column on me'
+);
+
+is_deeply(
+ [ $cds->_remap_identifiers(Identifier('artist', 'name')) ],
+ [ Identifier('artist', 'name'), [ { artist => {} } ] ],
+ 'Remap column on rel'
+);
+
+is_deeply(
+ [ $cds->search({}, { join => { single_track => { cd => 'artist' } } })
+ ->_remap_identifiers(Identifier('artist', 'name')) ],
+ [ Identifier('artist_2', 'name'), [ { artist => {} } ] ],
+ 'Remap column on rel with re-alias'
+);
+
+done_testing;