From: Matt S Trout Date: Sun, 24 Nov 2013 03:30:45 +0000 (+0000) Subject: don't accept relationship names as final identifier parts in remap X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d3ef20f069ab8479a95a96bde3a5e101e30042a;p=dbsrgits%2FDBIx-Class.git don't accept relationship names as final identifier parts in remap --- diff --git a/lib/DBIx/Class/ResultSet/Role/DQMethods.pm b/lib/DBIx/Class/ResultSet/Role/DQMethods.pm index ed4eb4c..83882e3 100644 --- a/lib/DBIx/Class/ResultSet/Role/DQMethods.pm +++ b/lib/DBIx/Class/ResultSet/Role/DQMethods.pm @@ -47,6 +47,7 @@ sub _remap_identifiers { my $seen_join = { %{$attrs->{seen_join}||{}} }; my $storage = $self->result_source->storage; my @need_join; + my %seen_op; my $mapped = map_dq_tree { return $_ unless is_Identifier; my @el = @{$_->{elements}}; @@ -65,6 +66,9 @@ sub _remap_identifiers { $p->{''} = { -alias => $alias, -rsrc => $rsrc }; } my $info = $p->{''}; + if ($info->{-rsrc}->has_relationship($last)) { + die "Invalid name on ".(join(',',@el)||'me').": $last is a relationship"; + } my $col_map = $info->{-column_mapping} ||= do { my $colinfo = $info->{-rsrc}->columns_info; +{ map +(($colinfo->{$_}{rename_for_dq}||$_) => $_), keys %$colinfo } diff --git a/t/dq/remap.t b/t/dq/remap.t index cc90954..83a2774 100644 --- a/t/dq/remap.t +++ b/t/dq/remap.t @@ -27,6 +27,10 @@ is_deeply( 'Remap column on me' ); +throws_ok { + $cds->_remap_identifiers(Identifier('artist')) +} qr/Invalid name on me: artist is a relationship/; + is_deeply( [ $cds->_remap_identifiers(Identifier('artist', 'name')) ], [ Identifier('artist', 'name'), [ { artist => {} } ] ],