我有一个定义了var $ hasMany = array("Comment")的博客模型;
如何在"评论"中应用过滤器以仅选择与特定评论类别匹配的博客项目?
如果,在博客模型中,我这样做
$this->recursive=2;
$this->hasMany=array("Comment"); //in Comment i have $belongsTo("Blog")
return $this->find("all",array("conditions"=>array("Comment.comment_type_id"=>123)));
Run Code Online (Sandbox Code Playgroud)
我收到一条错误,上面写着Unknown Comment.comment_type_id列,因为Cake没有进行连接.
我认为这是一个相当普遍的问题,所以我相信简单的解决但我找不到一个好方法
小智 8
$this->bindModel(array(
'hasMany' => array(
'Comment' => array(
'conditions' => array('Comment.comment_type_id' => 123)
))));
$this->find('all');
Run Code Online (Sandbox Code Playgroud)
或者如果模型已经使用注释使用绑定:
$this->hasMany['Comment']['conditions'] = array('Comment.comment_type_id' => 123);
$this->find('all');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8238 次 |
| 最近记录: |