Re: linking on differently-named foreign keys

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

From: Cees Hek
Subject: Re: linking on differently-named foreign keys
Date: 19:07 on 14 Feb 2005
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

(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
Cees Hek 19:07 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