[Dbix-class] BUG? Unable to resolve relationship

Peter Rabbitson rabbit+dbic at rabbit.us
Tue Dec 15 10:14:09 GMT 2009


Zbigniew Lukasiak wrote:
> On Sat, Dec 12, 2009 at 11:21 AM, Peter Rabbitson <rabbit+dbic at rabbit.us> wrote:
>> Zbigniew Lukasiak wrote:
>>> One additional question - what is the relation between 'belongs_to'
>>> and 'might_have' etc and 'add_relationship'?  I always thought that
>>> the first ones are only sugar for the last.  But unfortunately
>>> 'add_relationship' does not add an appropriate methods to the row
>>> class.
>> It does, you're just looking at the wrong one. Here is the rough chain
>> of events:
>>
>> ::Relationship::HasMany::has_many()
>>  ->  ::ResultSourceProxy::add_relationship()
>>    -> ::ResultSource::add_relationship()
>>    -> ::Relationship::ProxyMethods::register_relationship()
>>    -> ::Relationship::Accessor::register_relationship()
>>      -> ::Relationship::Accessor::add_relationship_accessor()
>>
> 
> How should I invoke it to add them?  When I change the line in question to:
> 
> The::Schema::Customer->add_relationship( "account", "The::Schema::Account",
>     { "foreign.id" => "self.account_id" } );
> 
> and run the program I get:
> 
> zby at zby:~/progs/tmp$ perl a.pl
> Can't locate object method "account" via package
> "The::Schema::Customer" at a.pl line 35.
> zby at zby:~/progs/tmp$
> 

Correct, because relationships are instantiated at source-within-schema
registration time. Once you have loaded your result classes into a schema
bundle, you can not add more relationships between them. If you must -
you need to re-register the source afterwards.



More information about the DBIx-Class mailing list