From: Daniel Westermann-Clark Date: Fri, 7 Jul 2006 07:05:34 +0000 (+0000) Subject: Take into account values specified in the where attr when deciding to include a uniqu... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=046a11c3f3b782279a9b3b9b073fe1893e9baca1;p=dbsrgits%2FDBIx-Class-Historic.git Take into account values specified in the where attr when deciding to include a unique query --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4f5f722..f4dcd65 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -365,6 +365,7 @@ sub find { sub _unique_queries { my ($self, $query, $attrs) = @_; + my $alias = $self->{attrs}{alias}; my @constraint_names = exists $attrs->{key} ? ($attrs->{key}) : $self->result_source->unique_constraint_names; @@ -374,15 +375,21 @@ sub _unique_queries { my @unique_cols = $self->result_source->unique_constraint_columns($name); my $unique_query = $self->_build_unique_query($query, \@unique_cols); - next unless scalar keys %$unique_query; + my $num_query = scalar keys %$unique_query; + next unless $num_query; # Add the ResultSet's alias - my $alias = $self->{attrs}{alias}; - foreach my $key (grep { ! m/\./ } keys %$unique_query) { - $unique_query->{"$alias.$key"} = delete $unique_query->{$key}; + foreach my $col (grep { ! m/\./ } keys %$unique_query) { + $unique_query->{"$alias.$col"} = delete $unique_query->{$col}; } - push @unique_queries, $unique_query; + # XXX: Assuming quite a bit about $self->{attrs}{where} + my $num_cols = scalar @unique_cols; + my $num_where = exists $self->{attrs}{where} + ? scalar keys %{ $self->{attrs}{where} } + : 0; + push @unique_queries, $unique_query + if $num_query + $num_where == $num_cols; } return @unique_queries; @@ -555,9 +562,9 @@ sub _collapse_query { } else { # warn "LEAF: " . Dumper $query; - foreach my $key (keys %$query) { - my $value = $query->{$key}; - $collapsed->{$key}{$value}++; + foreach my $col (keys %$query) { + my $value = $query->{$col}; + $collapsed->{$col}{$value}++; } } }