[Dbix-class] CDBI migration - link tables

Matt S Trout dbix-class at trout.me.uk
Tue Jan 10 01:36:21 CET 2006


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.

-- 
     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