I got a table with a few columns.
The table has a primary key (replyid), and two foreigne keys (userid and postid).
Here is the structure of the table: {replyid, content, userid, postid}
The Reply table got two foreigne keys.
I am not sure if this is a correct to set the foreign keys like this:
class Post extends AppModel{
var $name = 'Post';
var $useTable = 'post';
var $primaryKey = 'postid';
var $belongsTo = 'User';
var $hasMany = array(
'Reply' => array(
'className' => 'Reply',
'foreignKey' => 'postid',
'foreignKey' => 'userid'
)
);
}
?>
Could you helpplease?
Two foreign keys are fine,but you should define the relationshions in right models.
In your post model,
var $hasMany = array(
'Reply' => array(
'className' => 'Reply',
'foreignKey' => 'postid',
//'foreignKey' => 'userid'
)
);
In your user model,
var $hasMany = array(
'Reply' => array(
'className' => 'Reply',
//'foreignKey' => 'postid',
'foreignKey' => 'userid'
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With