[Bast-commits] r4094 - in DBIx-Class/0.08/branches/cdbicompat_integration: lib/DBIx/Class/CDBICompat t/cdbi-t

schwern at dev.catalyst.perl.org schwern at dev.catalyst.perl.org
Sun Feb 24 09:12:46 GMT 2008


Author: schwern
Date: 2008-02-24 09:12:46 +0000 (Sun, 24 Feb 2008)
New Revision: 4094

Added:
   DBIx-Class/0.08/branches/cdbicompat_integration/t/cdbi-t/has_many_loads_foreign_class.t
Modified:
   DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/CDBICompat/Relationships.pm
Log:
Ensure that has_many() loads the foreign class.

Modified: DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/CDBICompat/Relationships.pm
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/CDBICompat/Relationships.pm	2008-02-21 13:54:59 UTC (rev 4093)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/lib/DBIx/Class/CDBICompat/Relationships.pm	2008-02-24 09:12:46 UTC (rev 4094)
@@ -82,6 +82,7 @@
   }
 
   if( !$f_key and !@f_method ) {
+      $class->ensure_class_loaded($f_class);
       my $f_source = $f_class->result_source_instance;
       ($f_key) = grep { $f_source->relationship_info($_)->{class} eq $class }
                       $f_source->relationships;

Added: DBIx-Class/0.08/branches/cdbicompat_integration/t/cdbi-t/has_many_loads_foreign_class.t
===================================================================
--- DBIx-Class/0.08/branches/cdbicompat_integration/t/cdbi-t/has_many_loads_foreign_class.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/cdbicompat_integration/t/cdbi-t/has_many_loads_foreign_class.t	2008-02-24 09:12:46 UTC (rev 4094)
@@ -0,0 +1,37 @@
+use strict;
+use Test::More;
+
+
+BEGIN {
+  eval "use DBIx::Class::CDBICompat;";
+  plan skip_all => 'Class::Trigger and DBIx::ContextualFetch required' if $@;
+  eval "use DBD::SQLite";
+  plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 3);
+}
+
+
+use lib 't/testlib';
+use Director;
+
+# Test that has_many() will load the foreign class.
+ok !Class::Inspector->loaded( 'Film' );
+ok eval { Director->has_many( films => 'Film' ); 1; } || diag $@;
+
+my $shan_hua = Director->create({
+    Name    => "Shan Hua",
+});
+
+my $inframan = Film->create({
+    Title       => "Inframan",
+    Director    => "Shan Hua",
+});
+my $guillotine2 = Film->create({
+    Title       => "Flying Guillotine 2",
+    Director    => "Shan Hua",
+});
+my $guillotine = Film->create({
+    Title       => "Master of the Flying Guillotine",
+    Director    => "Yu Wang",
+});
+
+is_deeply [sort $shan_hua->films], [sort $inframan, $guillotine2];
\ No newline at end of file




More information about the Bast-commits mailing list