From: David Kamholz Date: Wed, 22 Nov 2006 06:44:26 +0000 (+0000) Subject: - slight optimization to ident_condition in PK.pm X-Git-Tag: v0.08010~215 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e04df8eca9c7bffa47dc33a45e44634e0b908651;p=dbsrgits%2FDBIx-Class.git - slight optimization to ident_condition in PK.pm - get ident_cond in update() before applying arguments, so a column's pk can be updated --- diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index ea22a21..9b9f8a4 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -99,8 +99,8 @@ Produces a condition hash to locate a row based on the primary key(s). sub ident_condition { my ($self, $alias) = @_; my %cond; - $cond{(defined $alias ? "${alias}.$_" : $_)} = $self->get_column($_) - for $self->primary_columns; + my $prefix = defined $alias ? $alias.'.' : ''; + $cond{$prefix.$_} = $self->get_column($_) for $self->primary_columns; return \%cond; } diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 57f883f..213f3cc 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -110,12 +110,12 @@ required. sub update { my ($self, $upd) = @_; $self->throw_exception( "Not in database" ) unless $self->in_storage; - $self->set_columns($upd) if $upd; - my %to_update = $self->get_dirty_columns; - return $self unless keys %to_update; my $ident_cond = $self->ident_condition; $self->throw_exception("Cannot safely update a row in a PK-less table") if ! keys %$ident_cond; + $self->set_columns($upd) if $upd; + my %to_update = $self->get_dirty_columns; + return $self unless keys %to_update; my $rows = $self->result_source->storage->update( $self->result_source->from, \%to_update, $ident_cond); if ($rows == 0) {