[Dbix-class] Backrefernce to parent object

Peter Rabbitson rabbit+dbic at rabbit.us
Mon Oct 4 13:05:49 GMT 2010


Rob Kinyon wrote:
> On Mon, Oct 4, 2010 at 04:02, Peter Rabbitson <rabbit+dbic at rabbit.us> wrote:
>> Rolf Schaufelberger wrote:
>>> Hi,
>>> suppose  I have a table  users  and a table address with a many-to many
>>> relation between users and addresses.
>>>
>>> Now when I fetch a user object and I call an address method    like
>>> $user->address({  search args})->first->do_something()
>>> Is there a way   in do_someting to access  the calling user object ?
>> This boils down to "if I have an $address how do I get the user it
>> belongs_to".
>> Which in turn requires you simply declare a belongs_to relationship on
>> Address pointing to User. Or am I missing something here?
> 
> Peter - you're missing the "many-to-many" relationship bit.
> 
> Rolf - a Row object is completely stand-alone. There is no direct
> relationship between the $user that did the search and the $address.
> You're going to have to pass $user into do_something() if you want to
> have access to it.
> 

What Rob said above. Apologies for missing a crucial part of the
question :)



More information about the DBIx-Class mailing list