X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FPK.pm;h=b2efdf8b2c02050fe9605cacd001578acf485e57;hb=2156bbddf88e67ebe429789d0018c708cddfcbe4;hp=9895edb24c16c1ab3aa58d150efdc6656995412f;hpb=9b83fccd091065fcebbb6fb6fb7bf2c2da38ffe2;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index 9895edb..b2efdf8 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -20,11 +20,6 @@ depending on them. =cut -sub _ident_cond { - my ($class) = @_; - return join(" AND ", map { "$_ = ?" } $class->primary_columns); -} - sub _ident_values { my ($self) = @_; return (map { $self->{_column_data}{$_} } $self->primary_columns); @@ -35,20 +30,30 @@ sub _ident_values { Re-selects the row from the database, losing any changes that had been made. +This method can also be used to refresh from storage, retrieving any +changes made since the row was last read from storage. + =cut sub discard_changes { my ($self) = @_; delete $self->{_dirty_columns}; return unless $self->in_storage; # Don't reload if we aren't real! - my ($reload) = $self->result_source->resultset->find - (map { $self->$_ } $self->primary_columns); + + my $reload = $self->result_source->resultset->find( + map { $self->$_ } $self->primary_columns + ); unless ($reload) { # If we got deleted in the mean-time $self->in_storage(0); return $self; } - delete @{$self}{keys %$self}; - @{$self}{keys %$reload} = values %$reload; + + %$self = %$reload; + + # Avoid a possible infinite loop with + # sub DESTROY { $_[0]->discard_changes } + bless $reload, 'Do::Not::Exist'; + return $self; } @@ -104,8 +109,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; }