[Dbix-class] Multiple belongs_to relationships referencing same class

Tobias Kremer list at funkreich.de
Wed Apr 25 21:30:59 GMT 2007


Hi folks,

I have a table which has two columns referencing the same class,  
something like this:

"id, user1_id, user2_id"

Both, user1_id and user2_id, contain User object ids.

Unfortunately I'm unable to set up two independent belongs_to  
relationships. I tried
this in my UserRelation class:

__PACKAGE__->belongs_to( 'requestor', 'My::Schema::User',  
{ 'foreign.id' => 'self.user1_id' }, { proxy => [ qw/id username/ ] } );
__PACKAGE__->belongs_to( 'receiver',  'My::Schema::User',  
{ 'foreign.id' => 'self.user2_id' }, { proxy => [ qw/id username/ ] } );

Depending on the order of these statements I get different results.

My User class has the following has_many relations:

__PACKAGE__->has_many( requested => 'My::Schema::UserRelation',  
{ 'foreign.user1_id' => 'self.id' } );
__PACKAGE__->has_many( received  => 'My::Schema::UserRelation',  
{ 'foreign.user2_id' => 'self.id' } );

$user->requested should return user2_id User objects, whereas $user- 
 >received should return user1_id User objects. But this
doesn't work as intended. I suppose that proxy is unable to determine  
the appropriate User object.

It's probably just me messing things up, but maybe there's some  
switch which allows me to do what I want.

Thanks!

--Tobias

_______________________________________/\____ _ .  .
+ web ::::::: http://www.funkreich.de
+ last.fm ::: http://www.last.fm/user/soulchild77
----------------------------------------------- -- -  -



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070425/3c1bb53a/attachment.htm


More information about the Dbix-class mailing list