[Dbix-class] RFC: $row->is_same_row($other_row_object)
Ashley
apv at sedition.com
Wed Jan 14 06:13:32 GMT 2009
I think the DBIC::Row would benefit from an "is_same_row" method.
This occurred to me while working on a Cat app wherein the primary
keys might be UUIDs instead of INTs. That means that code like -- $c-
>user->id == $whatever->user->id -- is wrong. This particular case
is easy enough to fix with "eq" but it got me thinking about multi-
col primary keys and isSameNode in LibXML and that -- $c->user-
>is_same_row($whatever) -- seems much cleaner and less likely to
break than some other practices.
So, I'm just throwing the idea out. Here is a stab, *untested* and
from someone who doesn't know DBIC's guts, at what it might look like-
=head2 is_same_row
if ( $obj1->is_same_row($obj2) ) {
print "Objects 1 and 2 are the same record\n";
}
And maybe an additional arg to do a "deep" check by refreshing
objects and comparing all their data(?).
$obj1->is_same_row($obj2,1) # code for this is *not* included below.
sub is_same_row {
my $self = shift;
my $other = shift || return;
my @pk1 = $self->id; # Are these returned in reliable order?
my @pk2 = $other->id;
return unless @pk1 == @pk2;
return unless blessed($self) eq blessed($other);
for ( 0 .. $#pk1 ) {
return unless "$pk1[$_]" eq "$pk2[$_]";
}
return 1;
}
Thanks for looking!
-Ashley
More information about the DBIx-Class
mailing list