Re: linking on differently-named foreign keys

[prev] [thread] [next] [Date index for 2005/02/14]

From: Ofer Nave
Subject: Re: linking on differently-named foreign keys
Date: 19:43 on 14 Feb 2005
Cees Hek wrote:

>On Mon, 14 Feb 2005 10:44:54 -0800, Ofer Nave <onave@xxxxxxxxx.xxx> wrote:
>  
>
>>15:Message->has_a( sender   => 'Account' );
>>16:Message->has_a( receiver => 'Account' );
>>---
>>
>>So the one thing I still don't get is, on lines 15-16, how does the
>>Message class figure out that it's the 'sender_id' field that needs to
>>be inflated into an object of the Account class when the sender() method
>>is called?  Is it because the Account class already knows about it's
>>side of the one-to-many relationship, and the Message class uses the
>>Account class's defined relationships to work out it's end of the deal?
>>    
>>
>
>You need to use the actual column name in the call to has_a.
>
>Message->has_a( sender_id   => 'Account' );
>Message->has_a( receiver_id => 'Account' );
>
>Class::DBI already knows that 'Account' is a Class::DBI object, so it
>automatically uses the primary key that was defined in the 'Account'
>class, and links it to the column name you specified in the has_a
>call.
>
>Cheers,
>
>Cees
>  
>
I see.  Of course, I want to say Message->sender() as opposed to 
Message->sender_id(), since it is returning an Account object, not a 
unique identifier... but I guess I do that by explicitly coding the 
sender() subroutine in the Message class, right?

-ofer

(message missing)

linking on differently-named foreign keys
Ofer Nave 08:38 on 14 Feb 2005

Re: linking on differently-named foreign keys
Tony Bowden 08:47 on 14 Feb 2005

Re: linking on differently-named foreign keys
Tony Bowden 09:50 on 14 Feb 2005

Re: linking on differently-named foreign keys
Ofer Nave 19:43 on 14 Feb 2005

Re: linking on differently-named foreign keys
Edward J. Sabol 20:00 on 14 Feb 2005

Generated at 17:31 on 15 Feb 2005 by mariachi v0.52