sub discard_changes {
my ($self) = @_;
- my $storage = $self->result_source->schema->storage;
- $storage->reload_row($self);
+ delete $self->{_dirty_columns};
+ return unless $self->in_storage; # Don't reload if we aren't real!
+
+ 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;
+ }
+
+ %$self = %$reload;
+
+ # Avoid a possible infinite loop with
+ # sub DESTROY { $_[0]->discard_changes }
+ bless $reload, 'Do::Not::Exist';
+
return $self;
}
=head2 reload_row ($row)
-given a L<DBIx::Class::Row> object, 'reloads' it from the storage. This will
-destroy any existing changes you have not yet saved.
+given a L<DBIx::Class::Row> object, loads and returns the matching version from
+storage. Does not effect the existing row object.
=cut
return @row;
}
-sub reload_row {
- my ($self, $row) = @_;
- delete $row->{_dirty_columns};
- return unless $row->in_storage; # Don't reload if we aren't real!
-
- my $reload = $row->result_source->resultset->find(
- map { $row->$_ } $row->primary_columns
- );
- unless ($reload) { # If we got deleted in the mean-time
- $row->in_storage(0);
- return $row;
- }
-
- $row = %$reload;
-
- # Avoid a possible infinite loop with
- # sub DESTROY { $_[0]->discard_changes }
- bless $reload, 'Do::Not::Exist';
-
- return $row;
+sub reload_row {
+ my ($self, $row) = @_;
+
+ my $reload = $row->result_source->resultset->find(
+ map { $row->$_ } $row->primary_columns
+ );
+
+ return $reload;
}
=head2 sth
around 'reload_row' => sub {
my ($reload_row, $self, $row) = @_;
- $self->execute_reliably(sub {
- $self->$reload_row(shift);
+ return $self->execute_reliably(sub {
+ return $self->$reload_row(shift);
}, $row);
};