From: Daniel Westermann-Clark Date: Fri, 26 May 2006 04:14:48 +0000 (+0000) Subject: Use stricter find in update_or_create again X-Git-Tag: v0.07002~75^2~155^2~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b40d2ec76d19e0cfd76cb77ef648bdd566f045df;p=dbsrgits%2FDBIx-Class.git Use stricter find in update_or_create again --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 1e86d85..0b9d84f 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1391,34 +1391,15 @@ unique constraints, see L. sub update_or_create { my $self = shift; my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {}); - my $hash = ref $_[0] eq 'HASH' ? shift : {@_}; + my $cond = ref $_[0] eq 'HASH' ? shift : {@_}; - my @constraint_names = exists $attrs->{key} - ? ($attrs->{key}) - : $self->result_source->unique_constraint_names; - $self->throw_exception( - "update_or_create requires a primary key or unique constraint; none is defined on " - . $self->result_source->name - ) unless @constraint_names; - - my @unique_queries; - foreach my $name (@constraint_names) { - my @unique_cols = $self->result_source->unique_constraint_columns($name); - my $unique_query = $self->_build_unique_query($hash, \@unique_cols); - - push @unique_queries, $unique_query - if keys %$unique_query == @unique_cols; - } - - if (@unique_queries) { - my $row = $self->single(\@unique_queries); - if (defined $row) { - $row->update($hash); - return $row; - } + my $row = $self->find($cond); + if (defined $row) { + $row->update($cond); + return $row; } - return $self->create($hash); + return $self->create($cond); } =head2 get_cache