[Dbix-class] Rows

Ian Docherty dbix-class at iandocherty.com
Fri Jul 27 14:24:11 GMT 2012


On 27 July 2012 14:48, Erik Colson <eco at ecocode.net> wrote:
> Patrick Meidl <patrick at pantheon.at> writes:
>
>> On Fri, Jul 27 2012, Erik Colson <eco at ecocode.net> wrote:
>>
>>> How can I check if the contents of 2 Row Objects are identical ?  I'm
>>> used to create a function to check the individual fields, but maybe
>>> DBIx::Class is smarter on this ?
>>
>> in ORM, identity is usually defined by having the same primary key. if
>> you maniplulate your objects after fetching them from the database,
>> though, you will have to do dirty checking (i.e. check if any columns
>> were changed in the detached object). you can use e.g. $row->is_changed
>> for this, see
>>
>> http://search.cpan.org/~frew/DBIx-Class-0.08198/lib/DBIx/Class/Row.pm#is_changed
>>
>> HTH
>>
>>     patrick
>
> Hi Patrick,
>
> That is one thing I want to check.. Thank you for the link !
>
> I also ant to now if somenone else did change anything in the row as
> saved in the database. I can achieve this by adding a serial field which
> increases at every update, but hence, maybe DBIx::Class has something
> for this too ;)
>
> --
> erik
You just need to read a bit further down that same link :)

You can either use
http://search.cpan.org/~frew/DBIx-Class-0.08198/lib/DBIx/Class/Row.pm#get_from_storage
to get a fresh copy which you can compare with the one you have, or
alternatively, just call 'discard_changes' to reselect
the current object from the database and get the latest version.

Regards
Ian



More information about the DBIx-Class mailing list