views:

205

answers:

1

Based on cakePHP's data model conventions, to setup a foreign key I would specify a column with the source_table followed by an _id.

I have an accounts and an account_messages table. Now the complication arises when I need 2 foreign key references to the same accounts table. Specifically I need to keep track of the account_id in the TO field and the account_id in the FROM field on a message.

From the docs/bakery, I would specify account_id.. however what would I specify for the second reference?!?

Is this possible and still benefit from cakePHP's magic code?

Any insight would be appreciated.

Ry

+5  A: 

I usually will do something like having a to_id and a from_id and then use something like http://book.cakephp.org/view/851/Multiple-relations-to-the-same-model

I think all that you need is in that link

HTH Sam

Sam D
+1 - as I suspected... though I think this is outside the scope of what's called "cakePHP's magic code".
LeguRi
Convention over configuration. Cake assume's the foreign key is named `{model}_id` by convention, but you can configure it to be anything you like.
deizel