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
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};
}
}