[Dbix-class] discard_changes upgrade.

Matt S Trout dbix-class at trout.me.uk
Sun Apr 6 20:27:21 BST 2008


On Tue, Mar 25, 2008 at 11:54:24AM +0300, Oleg Pronin wrote:
> Hello.
> 
> I think 'discard_changes' should be upgraded because:
> - it clears all the data in object. Suppose there was non-db data in the
> object:
>      __PACKAGE__->mk_accessors(....);
>   'discard_changes' clears it all. I think this is not good.
> 
> - it does not accept $attrs. For example there is often a need to refresh
> object from database with
>   exclusive lock, like $row->discard_changes({lock_for => 'update'});
> 
> - I think it should fetch only data without a need of constructing a heavy
> object. I.e.
> 
>     my ($self, $attrs) = @_;
>     return unless $self->in_storage;
> 
>     my $rs = $self->result_source->resultset;
>     $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
> 
>     my $hash_ref = $rs->find({
>         map { $_ => $self->get_column($_) } $self->primary_columns,
>     }, $attrs);
> 
>     $self->set_columns($hash_ref);
>     delete $self->{_dirty_columns};
> 
> 
> With best regards.

Could you attach the tests as well please?

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list