From: Matt S Trout Date: Tue, 10 Jul 2007 18:25:34 +0000 (+0000) Subject: fixes to multi-create X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a8c981748ab7ef605367a1a22330ab3e20bc5755;p=dbsrgits%2FDBIx-Class-Historic.git fixes to multi-create --- diff --git a/Changes b/Changes index c9c7bea..a0402f7 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class + - fixed up multi_create to be more intelligent about PK<->PK rels - fix many-many rels to not use set_columns - Unmarked deploy as experimental since it isn't anymore - Removed Cwd dep since it's not required and causes problems diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 332171a..bb727d8 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -164,24 +164,38 @@ sub insert { my @pri = $self->primary_columns; REL: foreach my $relname (keys %related_stuff) { - my $keyhash = $source->resolve_condition( - $source->relationship_info($relname)->{cond}, - undef, 1 - ); # the above argset gives me the dependent cols on self + + my $rel_obj = $related_stuff{$relname}; + + next REL unless (Scalar::Util::blessed($rel_obj) + && $rel_obj->isa('DBIx::Class::Row')); + + my $cond = $source->relationship_info($relname)->{cond}; + + next REL unless ref($cond) eq 'HASH'; + + # map { foreign.foo => 'self.bar' } to { bar => 'foo' } + + my $keyhash = { map { my $x = $_; $x =~ s/.*\.//; $x; } reverse %$cond }; # assume anything that references our PK probably is dependent on us - # rather than vice versa + # rather than vice versa, unless the far side is (a) defined or (b) + # auto-increment foreach my $p (@pri) { - next REL if exists $keyhash->{$p}; + if (exists $keyhash->{$p}) { + warn $keyhash->{$p}; + unless (defined($rel_obj->get_column($keyhash->{$p})) + || $rel_obj->column_info($keyhash->{$p}) + ->{is_auto_increment}) { + next REL; + } + } } - my $rel_obj = $related_stuff{$relname}; - if(Scalar::Util::blessed($rel_obj) && $rel_obj->isa('DBIx::Class::Row')) { - $rel_obj->insert(); - $self->set_from_related($relname, $rel_obj); - delete $related_stuff{$relname}; - } + $rel_obj->insert(); + $self->set_from_related($relname, $rel_obj); + delete $related_stuff{$relname}; } }