From: Daniel Westermann-Clark Date: Sat, 27 May 2006 22:06:35 +0000 (+0000) Subject: Relax _unique_queries for *_related X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=68c9468725220fe409987fa46bd73676460adb53;p=dbsrgits%2FDBIx-Class-Historic.git Relax _unique_queries for *_related --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 86b0b7e..d5df976 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -309,22 +309,22 @@ sub find { } else { # Compatibility: Allow e.g. find(id => $value) - carp "find by key => value deprecated; please use a hashref instead"; + carp "Find by key => value deprecated; please use a hashref instead"; $input_query = {@_}; } my @unique_queries = $self->_unique_queries($input_query, $attrs); -# use Data::Dumper; warn Dumper $self->result_source->name, $input_query, \@unique_queries; +# use Data::Dumper; warn Dumper $self->result_source->name, $input_query, \@unique_queries, $self->{attrs}->{where}; # Verify the query my $query = \@unique_queries; if (scalar @unique_queries == 0) { if (exists $attrs->{key}) { - $self->throw_exception("required values for the $attrs->{key} key not provided"); + $self->throw_exception("Required values for the $attrs->{key} key not provided"); } else { # Compatibility: Allow broken find usage for now - carp "find requires values for the primary key or a unique constraint" + carp "Query not guarnteed to return a single row" . "; please declare your unique constraints or use search instead"; $query = $input_query; } @@ -360,11 +360,11 @@ 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 == scalar @unique_cols; + next unless scalar keys %$unique_query; # Add the ResultSet's alias foreach my $key (grep { ! m/\./ } keys %$unique_query) { - $unique_query->{"$self->{attrs}{alias}.$key"} = delete $unique_query->{$key}; + $unique_query->{"$self->{attrs}->{alias}.$key"} = delete $unique_query->{$key}; } push @unique_queries, $unique_query; diff --git a/t/80unique.t b/t/80unique.t index 30767d2..46b8e47 100644 --- a/t/80unique.t +++ b/t/80unique.t @@ -98,7 +98,6 @@ is($cd7->year, $cd1->year, 'year is correct'); my $artist = $schema->resultset('Artist')->find($artistid); my $cd8 = $artist->find_or_create_related('cds', { - artist => $artistid, title => $title, year => 2020, }, @@ -112,7 +111,6 @@ is($cd8->year, $cd1->year, 'year is correct'); my $cd9 = $artist->update_or_create_related('cds', { - artist => $artistid, title => $title, year => 2021, },