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


_______________________________________________
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/[email protected]

Reply via email to