[Dbix-class] CDBI migration - link tables

Will Hawes info at whawes.co.uk
Mon Jan 9 11:12:19 CET 2006


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.



More information about the Dbix-class mailing list