Wednesday, May 23, 2012

Model Associations

Cake PHP 2.

public $useTable = 'Accounts';

/**

 * Primary key field

 *

 * @var string

 */

public $primaryKey = 'AccountID';

public $hasMany = array(

'Address' => array(

'className' => 'AccountAddress',

'foreignKey' => 'AccountID',

'conditions' => '',

'fields' => '',

'order' => ''

),

'Contact' => array(

'className' => 'CONTACT',

'foreignKey' => false,

'conditions'=>array(

'Contact.ACCOUNT_ID = Accounts.Account'

)

);


The Database was from an existing system.


AccountID = AccountID on the Account and the Address for the Account, no problems here.



The problem is the contacts. 

The join is Contact.Account_id = Accounts.Account (not Account_ID)

Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not be bound.


This join will always exist so I want to create it in the model class.  I am not able to change any DB Structure.

Thanks.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate