On 27 July 2012 14:48, Erik Colson <e...@ecocode.net> wrote: > Patrick Meidl <patr...@pantheon.at> writes: > >> On Fri, Jul 27 2012, Erik Colson <e...@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 _______________________________________________ List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/ Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk