X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSetColumn.pm;h=430e35b4efbfc91621dd2f9f8c83fbbfbdc6fbc1;hb=69cd8a7fcceed892f3bbd6cfba5804776033a85b;hp=ee1ed04b480b5a2b05056b64d91ab9817a4d744c;hpb=4e55c3ae65c1a0c1ef55043fb44bff52d1a1c5a1;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/ResultSetColumn.pm b/lib/DBIx/Class/ResultSetColumn.pm index ee1ed04..430e35b 100644 --- a/lib/DBIx/Class/ResultSetColumn.pm +++ b/lib/DBIx/Class/ResultSetColumn.pm @@ -1,7 +1,12 @@ package DBIx::Class::ResultSetColumn; + use strict; use warnings; + use base 'DBIx::Class'; + +use Carp::Clan qw/^DBIx::Class/; +use DBIx::Class::Exception; use List::Util; =head1 NAME @@ -61,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 @@ -76,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; @@ -414,10 +427,12 @@ See L for details. sub throw_exception { my $self=shift; + if (ref $self && $self->{_parent_resultset}) { - $self->{_parent_resultset}->throw_exception(@_) - } else { - croak(@_); + $self->{_parent_resultset}->throw_exception(@_); + } + else { + DBIx::Class::Exception->throw(@_); } }