[Dbix-class] compoase_namespace, add_column, and result_source_instance
Matt S Trout
dbix-class at trout.me.uk
Sat Jul 8 17:48:27 CEST 2006
Christopher H. Laco wrote:
> OK, this is my last post on the subject. I need to eat, and the wife
> actually wants to interact with me rather than watch me curse at the
> computer all morning.
>
> The talk of add_columns and Handel is a side road carnival show. It's a
> symptom of another problem.
>
> I believe that problem is this: compose_namespace clones a schema, then
> creates new classes. The result of compose_namespace is a schema object
> in which its sources are new, not the original sources, and the source
> classes are new, also not the originals. The fault lie inthe fact that
> the new source classes aren't tied to the new source objects via
> result_source_instance.
>
> Instead, class->result_source_instance is inherited, and still points to
> the original pre-cloned sources.
>
> The following patch fixes the problem for me, and the basic test suite
> still passes for me. I can't speak for the mysql/pg tests. Someone
> please try those just for the sake of my sanity.
>
>> Index: lib/DBIx/Class/Schema.pm
>> ===================================================================
>> --- lib/DBIx/Class/Schema.pm (revision 2145)
>> +++ lib/DBIx/Class/Schema.pm (working copy)
>> @@ -390,6 +390,7 @@
>> $target_class => $source->result_class, ($base ? $base : ())
>> );
>> $source->result_class($target_class);
>> + $target_class->result_source_instance($source);
>> }
>> }
>> Class::C3->reinitialize();
>
>
> The code actually speaks to my theory I think.
> The new sources' result_class is associated with the new class, but the
> reverse wasn't true.
>
> I wouldn't dare commit this since the topic is somewhat complicated. :-)
Other than doing an ->can check first to ensure the target class actually uses
ResultSourceProxy that seems fine. Shove it into -current, I consider this a
bugfix.
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list