Monday, 30 September 2013

CakePHP relations with different association keys

CakePHP relations with different association keys

I have two models User and Post. But the relation here is based on
username in both tables. ie. Post.username and User.username
I am trying with following hasMany relation in user.php with cakephp 1.3
'Post' => array(
'className' => 'Post',
'dependent' => true,
'foreignKey' => 'username',
'associatedKey' => 'username'
),
But it's not creating relations between both models, when i am trying to
fetch data using.
pr( $this->User->find('all') );
Here is the output even when posts are there for user 'vinni'
Array(
[User] => Array(
id => 2
name => 'Vinay',
username => 'vinni'
[Post] => Array
(
)
)
)

No comments:

Post a Comment