From: Ash Berlin Date: Wed, 27 Dec 2006 22:48:49 +0000 (+0000) Subject: Removed CDBI subclassing bugs. constrain_columns to work out now X-Git-Tag: v0.08010~150^2~112^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e87bedbe12121cef1c12b6fdd8afa3d863831175;p=dbsrgits%2FDBIx-Class.git Removed CDBI subclassing bugs. constrain_columns to work out now --- diff --git a/lib/DBIx/Class/DB.pm b/lib/DBIx/Class/DB.pm index e002377..9d80916 100644 --- a/lib/DBIx/Class/DB.pm +++ b/lib/DBIx/Class/DB.pm @@ -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 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 diff --git a/lib/DBIx/Class/ResultSourceProxy/Table.pm b/lib/DBIx/Class/ResultSourceProxy/Table.pm index 0816dd7..ce78cb8 100644 --- a/lib/DBIx/Class/ResultSourceProxy/Table.pm +++ b/lib/DBIx/Class/ResultSourceProxy/Table.pm @@ -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); diff --git a/t/68inflate.t b/t/68inflate.t index 6cbc96d..7afb0e9 100644 --- a/t/68inflate.t +++ b/t/68inflate.t @@ -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',