Conditions in associated models using Model->find() (CakePHP)

后端 未结 4 1791
无人及你
无人及你 2020-12-15 10:56

I am having some issues with CakePHP\'s find() method and conditions in \'deeper\' model associations. There are some of these around but I could not find an answer to this

4条回答
  •  臣服心动
    2020-12-15 11:23

    $joins = array(
               array('table'=>'comments', 
                     'alias' => 'Comment',
                     'type'=>'inner',
                     'conditions'=> array(
                     'Comment.id = Vote.comment_id'
               )),
               array('table'=>'posts', 
                     'alias' => 'Post',
                     'type'=>'inner',
                     'conditions'=> array(
                     'Post.id = Comment.post_id'
               )),
               array('table'=>'users', 
                     'alias' => 'User',
                     'type'=>'inner',
                     'conditions'=> array(
                     'User.id = Post.user_id','User.id'=>$user_id
               ))
             );
    
    $votes = $this->Vote->find('all',array('joins'=>$joins,'recursive'=>-1));
    

提交回复
热议问题