[Bast-commits] r3881 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class
ash at dev.catalyst.perl.org
ash at dev.catalyst.perl.org
Thu Nov 15 13:52:58 GMT 2007
Author: ash
Date: 2007-11-15 13:52:58 +0000 (Thu, 15 Nov 2007)
New Revision: 3881
Modified:
DBIx-Class/0.08/trunk/Changes
DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm
Log:
Fix t/82cascade_copy.t
Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes 2007-11-15 13:02:15 UTC (rev 3880)
+++ DBIx-Class/0.08/trunk/Changes 2007-11-15 13:52:58 UTC (rev 3881)
@@ -17,6 +17,8 @@
- ResultSource::reverse_relationship_info can distinguish between
sources using the same table
- Row::insert will now not fall over if passed duplicate related objects
+ - Row::copy will not fall over if you have two relationships to the
+ same source with a unique constraint on it
0.08007 2007-09-04 19:36:00
- patch for Oracle datetime inflation (abram at arin.net)
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm 2007-11-15 13:02:15 UTC (rev 3880)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm 2007-11-15 13:52:58 UTC (rev 3881)
@@ -532,15 +532,29 @@
$new->result_source($self->result_source);
$new->set_columns($changes);
$new->insert;
+
+ # Its possible we'll have 2 relations to the same Source. We need to make
+ # sure we don't try to insert the same row twice esle we'll violate unique
+ # constraints
+ my $rels_copied = {};
+
foreach my $rel ($self->result_source->relationships) {
my $rel_info = $self->result_source->relationship_info($rel);
- if ($rel_info->{attrs}{cascade_copy}) {
- my $resolved = $self->result_source->resolve_condition(
- $rel_info->{cond}, $rel, $new);
- foreach my $related ($self->search_related($rel)) {
- $related->copy($resolved);
- }
+
+ next unless $rel_info->{attrs}{cascade_copy};
+
+ my $resolved = $self->result_source->resolve_condition(
+ $rel_info->{cond}, $rel, $new
+ );
+
+ my $copied = $rels_copied->{ $rel_info->{source} } ||= {};
+ foreach my $related ($self->search_related($rel)) {
+ my $id_str = join("\0", $related->id);
+ next if $copied->{$id_str};
+ $copied->{$id_str} = 1;
+ my $rel_copy = $related->copy($resolved);
}
+
}
return $new;
}
More information about the Bast-commits
mailing list