是否有可能创建一个hasMany关系,该关系使用模型之外的ID?例如,一个用户有很多评论,但我想找到登录的用户的只是评论:CakePHP,HasMany关系
public $hasMany = array(
'MyComment' => array(
'className' => 'Comment',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => array('Comment.user_id' => $loggedinUser_id),
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
我想传递$ loggedinUser_id在控制器beforeFilter()的模型。这是解决这个问题的好方法还是有更好的方法?
任何建议表示赞赏。 非常感谢!
我在这里得到了一个非常好的答案这个问题:http://stackoverflow.com/questions/3619891/hasmany-relationship-and-id-from-other-model-in-cakephp – chris 2010-09-02 09:18:38