Removed CDBI subclassing bugs. constrain_columns to work out now
Ash Berlin [Wed, 27 Dec 2006 22:48:49 +0000 (22:48 +0000)]
lib/DBIx/Class/DB.pm
lib/DBIx/Class/ResultSourceProxy/Table.pm
t/68inflate.t

index e002377..9d80916 100644 (file)
@@ -8,6 +8,7 @@ use DBIx::Class::Schema;
 use DBIx::Class::Storage::DBI;
 use DBIx::Class::ClassResolver::PassThrough;
 use DBI;
+use Scalar::Util;
 
 unless ($INC{"DBIx/Class/CDBICompat.pm"}) {
   warn "IMPORTANT: DBIx::Class::DB is DEPRECATED AND *WILL* BE REMOVED. DO NOT USE.\n";
@@ -140,13 +141,43 @@ native L<DBIx::Class::ResultSet> system.
 =cut
 
 sub resultset_instance {
-  my $class = ref $_[0] || $_[0];
-  my $source = $class->result_source_instance;
+  $_[0]->result_source_instance->resultset
+}
+
+sub result_source_instance {
+  my $class = shift;
+  $class = ref $class || $class;
+  __PACKAGE__->mk_classdata(qw/_result_source_instance/)
+    unless __PACKAGE__->can('_result_source_instance');
+
+  
+  return $class->_result_source_instance(@_) if @_;
+
+  my $source = $class->_result_source_instance;
+  return {} unless Scalar::Util::blessed($source);
+
   if ($source->result_class ne $class) {
-    $source = $source->new($source);
-    $source->result_class($class);
+    # Remove old source instance so we dont get deep recursion
+    #$DB::single = 1;
+    # Need to set it to a non-undef value so that it doesn't just fallback to
+    # a parent class's _result_source_instance
+    #$class->_result_source_instance({});
+    #$class->table($class);
+    #$source = $class->_result_source_instance;
+
+    $DB::single = 1;
+    $source = $source->new({ 
+        %$source, 
+        source_name  => $class,
+        result_class => $class
+    } );
+    $class->_result_source_instance($source);
+    if (my $coderef = $class->can('schema_instance')) {
+        $coderef->($class)->register_class($class, $class);
+    }
   }
-  return $source->resultset;
+  return $source;
 }
 
 =head2 resolve_class
index 0816dd7..ce78cb8 100644 (file)
@@ -53,7 +53,12 @@ sub table {
         source_name => undef,
     });
   }
-  $class->mk_classdata('result_source_instance' => $table);
+
+  $class->mk_classdata('result_source_instance')
+    unless $class->can('result_source_instance');
+
+  $class->result_source_instance($table);
+
   if ($class->can('schema_instance')) {
     $class =~ m/([^:]+)$/;
     $class->schema_instance->register_class($class, $class);
index 6cbc96d..7afb0e9 100644 (file)
@@ -7,15 +7,11 @@ use DBICTest;
 
 my $schema = DBICTest->init_schema();
 
-DBICTest::Schema::CD->add_column('year2');
-$DB::single = 1;
 eval { require DateTime };
 plan skip_all => "Need DateTime for inflation tests" if $@;
 
 plan tests => 4;
 
-$DB::single = 1;
-
 $schema->class('CD')
 #DBICTest::Schema::CD
 ->inflate_column( 'year',