[Dbix-class] discard_changes upgrade.

Oleg Pronin syber.rus at gmail.com
Tue Mar 25 08:54:24 GMT 2008


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 =3D> 'update'});

- I think it should fetch only data without a need of constructing a heavy
object. I.e.

    my ($self, $attrs) =3D @_;
    return unless $self->in_storage;

    my $rs =3D $self->result_source->resultset;
    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');

    my $hash_ref =3D $rs->find({
        map { $_ =3D> $self->get_column($_) } $self->primary_columns,
    }, $attrs);

    $self->set_columns($hash_ref);
    delete $self->{_dirty_columns};


With best regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20080325/0b5=
a800e/attachment.htm


More information about the DBIx-Class mailing list