From: John Napiorkowski Date: Thu, 29 May 2008 23:03:15 +0000 (+0000) Subject: changed Storage->reload_row to do less, reverted some behavior to PK->discard_changes... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=243a6b72cfb2a6f2ccfcd84b665f1880790e2ff9;p=dbsrgits%2FDBIx-Class-Historic.git changed Storage->reload_row to do less, reverted some behavior to PK->discard_changes. Did this to solve some capatibility issues with partitioning. updated docs to reflect this. --- diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index bb820e2..e281dd4 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -37,8 +37,22 @@ changes made since the row was last read from storage. 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; } diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index df4434e..e57a48b 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -440,8 +440,8 @@ sub select_single { die "Virtual method!" } =head2 reload_row ($row) -given a L object, 'reloads' it from the storage. This will -destroy any existing changes you have not yet saved. +given a L object, loads and returns the matching version from +storage. Does not effect the existing row object. =cut diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 6c9b97d..7d82eca 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1296,26 +1296,14 @@ sub select_single { 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 diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index efabb05..ad3fff1 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -492,8 +492,8 @@ the master storage. 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); };