Re: linking on differently-named foreign keys

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

From: Tony Bowden
Subject: Re: linking on differently-named foreign keys
Date: 08:47 on 14 Feb 2005
On Mon, Feb 14, 2005 at 12:38:47AM -0800, Ofer Nave wrote:
> CREATE TABLE account ( account_id INT );
> CREATE TABLE message ( sender_id INT, receiver_id INT );
> Let's say I want to create my Account class, and use Account->has_many() 
> to defined the methods inbox() and sent_mail().  Is there an elegant way 
> to tell CDBI to lookup the rows in the message table where 
> receiver_id=account_id for inbox() and sender_id=account_id for sent_mail()?

You give has_many a 3rd argument for the key to use:

Account->has_many(inbox => "Message", 'receiver_id');
Account->has_many(sent_mail => "Message", 'account_id');

Tony

(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
Edward J. Sabol 20:00 on 14 Feb 2005

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