changed Storage->reload_row to do less, reverted some behavior to PK->discard_changes...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / PK.pm
index ea22a21..e281dd4 100644 (file)
@@ -30,20 +30,29 @@ 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->schema->storage->reload_row($self);
+  
   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;
 }
 
@@ -99,8 +108,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;
 }