[Dbix-class] CDBI migration - link tables

Will Hawes info at whawes.co.uk
Tue Jan 10 10:38:00 CET 2006


Matt S Trout wrote:
> On Mon, Jan 09, 2006 at 10:12:19AM +0000, Will Hawes wrote:
>> Sorry about the dodgy thread title, the correct terminology escapes me 
>> on a Monday morning.
>>
>> Given the following (in CDBI):
>>
>> package User;
>> ...
>> __PACKAGE__->has_many(addresses => ['UserAddress' => 'address']);
>>
>> package UserAddress;
>> ...
>> __PACKAGE__->has_a(user => 'User');
>> __PACKAGE__->has_a(address => 'Address');
>>
>> package Address;
>> ...
>> __PACKAGE__->has_many(users => ['UserAddress' => 'user']);
>>
>> doing $user->addresses will return Address objects.
>>
>> DBIC doesn't seem to allow the same syntax to "bridge" the link table. 
>> How can $user->addresses be made to return Address objects under DBIC?
>>
>> This must be a reasonably common requirement so I'll be happy to 
>> contribute a Cookbook patch, assuming I haven't already missed this in 
>> the docs.
> 
> That's a many-many relationship. Cookbook has an example of how to do it
> against the 0.03+ series, and the branch (due to the implementation of
> search_related on resultsets) has a proper ->many_to_many helper.
> 

Right, thanks. Always read examples twice :)

You've lost me on the many_to_many helper - when you says it's a branch, 
what does that mean in terms of a release?



More information about the Dbix-class mailing list