[Bast-commits] r3583 - in trunk/DBIx-Class: . lib/DBIx/Class
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Tue Jul 10 19:25:35 GMT 2007
Author: matthewt
Date: 2007-07-10 19:25:34 +0100 (Tue, 10 Jul 2007)
New Revision: 3583
Modified:
trunk/DBIx-Class/Changes
trunk/DBIx-Class/lib/DBIx/Class/Row.pm
Log:
fixes to multi-create
Modified: trunk/DBIx-Class/Changes
===================================================================
--- trunk/DBIx-Class/Changes 2007-07-10 18:23:34 UTC (rev 3582)
+++ trunk/DBIx-Class/Changes 2007-07-10 18:25:34 UTC (rev 3583)
@@ -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
Modified: trunk/DBIx-Class/lib/DBIx/Class/Row.pm
===================================================================
--- trunk/DBIx-Class/lib/DBIx/Class/Row.pm 2007-07-10 18:23:34 UTC (rev 3582)
+++ trunk/DBIx-Class/lib/DBIx/Class/Row.pm 2007-07-10 18:25:34 UTC (rev 3583)
@@ -164,24 +164,38 @@
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};
}
}
More information about the Bast-commits
mailing list