Merge 'trunk' into 'rt_bug_41083'
Jason M. Mills [Tue, 10 Feb 2009 05:30:07 +0000 (05:30 +0000)]
Merged trunk in to rt_bug_t41083 branch via svk merge.

13 files changed:
lib/DBIx/Class/InflateColumn/DateTime.pm
lib/DBIx/Class/Row.pm
lib/DBIx/Class/Schema.pm
t/39load_namespaces_rt41083.t [new file with mode: 0644]
t/66relationship.t
t/96multi_create.t
t/lib/DBICNSTest/RtBug41083/ResultSet.pm [new file with mode: 0644]
t/lib/DBICNSTest/RtBug41083/ResultSet/Foo.pm [new file with mode: 0644]
t/lib/DBICNSTest/RtBug41083/ResultSet_A/A.pm [new file with mode: 0644]
t/lib/DBICNSTest/RtBug41083/Schema/Foo.pm [new file with mode: 0644]
t/lib/DBICNSTest/RtBug41083/Schema/Foo/Sub.pm [new file with mode: 0644]
t/lib/DBICNSTest/RtBug41083/Schema_A/A.pm [new file with mode: 0644]
t/lib/DBICNSTest/RtBug41083/Schema_A/A/Sub.pm [new file with mode: 0644]

index 3024241..85eab8a 100644 (file)
@@ -19,9 +19,6 @@ columns to be of the datetime, timestamp or date datatype.
     starts_when => { data_type => 'datetime' }
   );
 
-NOTE: You B<must> load C<InflateColumn::DateTime> B<before> C<Core>. See
-L<DBIx::Class::Manual::Component> for details.
-
 Then you can treat the specified column as a L<DateTime> object.
 
   print "This event starts the month of ".
index ba05001..518d6e8 100644 (file)
@@ -771,17 +771,24 @@ sub set_inflated_columns {
       {
         my $rel = delete $upd->{$key};
         $self->set_from_related($key => $rel);
-        $self->{_relationship_data}{$key} = $rel;
+        $self->{_relationship_data}{$key} = $rel;          
       } elsif ($info && $info->{attrs}{accessor}
-        && $info->{attrs}{accessor} eq 'multi') {
-          $self->throw_exception(
-            "Recursive update is not supported over relationships of type multi ($key)"
-          );
+        && $info->{attrs}{accessor} eq 'multi'
+        && ref $upd->{$key} eq 'ARRAY') {
+        my $others = delete $upd->{$key};
+        foreach my $rel_obj (@$others) {
+          if(!Scalar::Util::blessed($rel_obj)) {
+            $rel_obj = $self->create_related($key, $rel_obj);
+          }
+        }
+        $self->{_relationship_data}{$key} = $others; 
+#            $related->{$key} = $others;
+        next;
       }
       elsif ($self->has_column($key)
         && exists $self->column_info($key)->{_inflate_info})
       {
-        $self->set_inflated_column($key, delete $upd->{$key});
+        $self->set_inflated_column($key, delete $upd->{$key});          
       }
     }
   }
index 9222f80..1c75a50 100644 (file)
@@ -208,12 +208,16 @@ sub load_namespaces {
     local *Class::C3::reinitialize = sub { };
     use warnings 'redefine';
 
-    foreach my $result (keys %results) {
+    # ensure classes are loaded and fetch properly sorted classes
+    $class->ensure_class_loaded($_) foreach(values %results);
+    my @subclass_last = sort { $results{$a}->isa($results{$b}) } keys(%results);
+    
+    foreach my $result (@subclass_last) {
       my $result_class = $results{$result};
-      $class->ensure_class_loaded($result_class);
 
       my $rs_class = delete $resultsets{$result};
       my $rs_set = $result_class->resultset_class;
+      
       if($rs_set && $rs_set ne 'DBIx::Class::ResultSet') {
         if($rs_class && $rs_class ne $rs_set) {
           warn "We found ResultSet class '$rs_class' for '$result', but it seems "
diff --git a/t/39load_namespaces_rt41083.t b/t/39load_namespaces_rt41083.t
new file mode 100644 (file)
index 0000000..ba99fe5
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+use lib 't/lib';
+
+plan tests => 4;
+
+sub _chk_warning {
+       defined $_[0]? 
+               $_[0] !~ qr/We found ResultSet class '([^']+)' for '([^']+)', but it seems that you had already set '([^']+)' to use '([^']+)' instead/ :
+               1
+}
+
+my $warnings;
+eval {
+    local $SIG{__WARN__} = sub { $warnings .= shift };
+    package DBICNSTest::RtBug41083;
+    use base 'DBIx::Class::Schema';
+    __PACKAGE__->load_namespaces(
+       result_namespace => 'Schema_A',
+       resultset_namespace => 'ResultSet_A',
+       default_resultset_class => 'ResultSet'
+    );
+};
+ok(!$@) or diag $@;
+ok(_chk_warning($warnings), 'expected no complaint');
+
+eval {
+    local $SIG{__WARN__} = sub { $warnings .= shift };
+    package DBICNSTest::RtBug41083;
+    use base 'DBIx::Class::Schema';
+    __PACKAGE__->load_namespaces(
+       result_namespace => 'Schema',
+       resultset_namespace => 'ResultSet',
+       default_resultset_class => 'ResultSet'
+    );
+};
+ok(!$@) or diag $@;
+ok(_chk_warning($warnings), 'expected no complaint') or diag $warnings;
index fe0196c..94d7e87 100644 (file)
@@ -275,8 +275,6 @@ is ($@, '', 'Staged insertion successful');
 ok($new_artist->in_storage, 'artist inserted');
 ok($new_related_cd->in_storage, 'new_related_cd inserted');
 
-TODO: {
-local $TODO = "TODOify for multicreate branch";
 my $new_cd = $schema->resultset("CD")->new_result({});
 my $new_related_artist = $new_cd->new_related('artist', { 'name' => 'Marillion',});
 lives_ok (
@@ -300,4 +298,3 @@ cmp_ok($relinfo->{attrs}{is_foreign_key_constraint}, '==', 1, "is_foreign_key_co
 my $rs_overridden = $schema->source('ForceForeign');
 my $relinfo_with_attr = $rs_overridden->relationship_info ('cd_3');
 cmp_ok($relinfo_with_attr->{attrs}{is_foreign_key_constraint}, '==', 0, "is_foreign_key_constraint defined for belongs_to relationships with attr.");
-}
index 4445f3f..e202c59 100644 (file)
@@ -168,8 +168,6 @@ eval {
 };
 diag $@ if $@;
 
-TODO: {
-local $TODO = "Todoify for multicreate branch";
 # test might_have again but with a PK == FK in the middle (obviously not specified)
 eval {
   my $artist = $schema->resultset('Artist')->first;
@@ -260,7 +258,6 @@ eval {
   );
 };
 diag $@ if $@;
-}
 
 # nested find_or_create
 eval {
diff --git a/t/lib/DBICNSTest/RtBug41083/ResultSet.pm b/t/lib/DBICNSTest/RtBug41083/ResultSet.pm
new file mode 100644 (file)
index 0000000..2e30409
--- /dev/null
@@ -0,0 +1,5 @@
+package DBICNSTest::RtBug41083::ResultSet;
+use strict;
+use warnings;
+use base 'DBIx::Class::ResultSet';
+1;
diff --git a/t/lib/DBICNSTest/RtBug41083/ResultSet/Foo.pm b/t/lib/DBICNSTest/RtBug41083/ResultSet/Foo.pm
new file mode 100644 (file)
index 0000000..9bf912a
--- /dev/null
@@ -0,0 +1,8 @@
+package DBICNSTest::RtBug41083::ResultSet::Foo;
+use strict;
+use warnings;
+use base 'DBICNSTest::RtBug41083::ResultSet';
+
+sub fooBar { 1; }
+
+1;
diff --git a/t/lib/DBICNSTest/RtBug41083/ResultSet_A/A.pm b/t/lib/DBICNSTest/RtBug41083/ResultSet_A/A.pm
new file mode 100644 (file)
index 0000000..cb93955
--- /dev/null
@@ -0,0 +1,7 @@
+package DBICNSTest::RtBug41083::ResultSet_A::A;
+use strict;
+use warnings;
+use base 'DBICNSTest::RtBug41083::ResultSet';
+
+sub fooBar { 1; }
+1;
diff --git a/t/lib/DBICNSTest/RtBug41083/Schema/Foo.pm b/t/lib/DBICNSTest/RtBug41083/Schema/Foo.pm
new file mode 100644 (file)
index 0000000..11f10e9
--- /dev/null
@@ -0,0 +1,8 @@
+package DBICNSTest::RtBug41083::Schema::Foo;
+use strict;
+use warnings;
+use base 'DBIx::Class';
+__PACKAGE__->load_components('Core');
+__PACKAGE__->table('foo');
+__PACKAGE__->add_columns('foo');
+1;
diff --git a/t/lib/DBICNSTest/RtBug41083/Schema/Foo/Sub.pm b/t/lib/DBICNSTest/RtBug41083/Schema/Foo/Sub.pm
new file mode 100644 (file)
index 0000000..73ec679
--- /dev/null
@@ -0,0 +1,5 @@
+package DBICNSTest::RtBug41083::Schema::Foo::Sub;
+use strict;
+use warnings;
+use base 'DBICNSTest::RtBug41083::Schema::Foo';
+1;
diff --git a/t/lib/DBICNSTest/RtBug41083/Schema_A/A.pm b/t/lib/DBICNSTest/RtBug41083/Schema_A/A.pm
new file mode 100644 (file)
index 0000000..ca626d7
--- /dev/null
@@ -0,0 +1,8 @@
+package DBICNSTest::RtBug41083::Schema_A::A;
+use strict;
+use warnings;
+use base 'DBIx::Class';
+__PACKAGE__->load_components('Core');
+__PACKAGE__->table('a');
+__PACKAGE__->add_columns('a');
+1;
diff --git a/t/lib/DBICNSTest/RtBug41083/Schema_A/A/Sub.pm b/t/lib/DBICNSTest/RtBug41083/Schema_A/A/Sub.pm
new file mode 100644 (file)
index 0000000..1128e1e
--- /dev/null
@@ -0,0 +1,5 @@
+package DBICNSTest::RtBug41083::Schema_A::A::Sub;
+use strict;
+use warnings;
+use base 'DBICNSTest::RtBug41083::Schema_A::A';
+1;