From: Peter Rabbitson Date: Fri, 18 Sep 2009 12:25:06 +0000 (+0000) Subject: Minor cleanup of RSC with has_many joins X-Git-Tag: v0.08112~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=722c014094b566e9a61ad06ae9ef424bad02bc9e;p=dbsrgits%2FDBIx-Class.git Minor cleanup of RSC with has_many joins --- diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index bdb8652..430e35b 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -5,6 +5,7 @@ use warnings; use base 'DBIx::Class'; +use Carp::Clan qw/^DBIx::Class/; use DBIx::Class::Exception; use List::Util; @@ -65,7 +66,7 @@ sub new { my $select = defined $as_index ? $select_list->[$as_index] : $column; # {collapse} would mean a has_many join was injected, which in turn means - # we need to group IF WE CAN (only if the column in question is unique) + # we need to group *IF WE CAN* (only if the column in question is unique) if (!$new_attrs->{group_by} && keys %{$orig_attrs->{collapse}}) { # scan for a constraint that would contain our column only - that'd be proof @@ -80,9 +81,17 @@ sub new { if ($col eq $select or $fqcol eq $select) { $new_attrs->{group_by} = [ $select ]; + delete $new_attrs->{distinct}; # it is ignored when group_by is present last; } } + + if (!$new_attrs->{group_by}) { + carp ( + "Attempting to retrieve non-unique column '$column' on a resultset containing " + . 'one-to-many joins will return duplicate results.' + ); + } } my $new = bless { _select => $select, _as => $column, _parent_resultset => $new_parent_rs }, $class;