cakephp 1.3:找到条件

时间:2011-10-01 10:10:40

标签: cakephp cakephp-1.3

   Array
  (
     [0] => Array
       (
        [DebateComment] => Array
            (
                [id] => 126
                [user_id] => 17
                [debate_id] => 32
                [debate_comment_title] => hiiiiiii
                [debate_comments] => gfdfg dfg .

                [debate_type] => against
                [total_postive_counts] => 1
                [total_negative_counts] => 0
                [accept_challenges] => Enable
                [status] => Active
                [modified] => 2011-08-19 11:12:59
                [created] => 2011-08-18 17:50:53
            )

        [User] => Array
            (
                [id] => 17
                [group_id] => 3
                [fb_user_id] => 0
                [username] => xyz
                [email] => xyz@xyz.com
                [password] => 077dadf3cc9c5fcb95dfacc3d8ff5049123b2d89
                [status] => 1
                [verify_code] => 
                [signup_ip] => 
                [is_verified] => 1
                [user_comment_warn_status] => 0
                [user_ip_address] => 
                [referred_by_user_id] => 0
                [twitter_user_id] => 0
                [twitter_access_key] => 
                [twitter_access_token] => 
                [modified] => 2011-05-05 10:43:15
                [Userdetail] => Array
                    (
                        [id] => 14
                        [user_id] => 17
                        [firstname] => xyz
                        [lastname] => 
                        [about_me] => 
                        [tagline] => 

                        [visible_status] => Online

                        [show_welcome_message] => Yes
                        [created] => 2011-05-05 10:43:15
                        [modified] => 2011-05-05 10:43:15


                    )

                )
    )

上面的数组描述了彼此的关系。

我写了这个查询但是得到了输出。

$arr = $this->DebateComment->find('all',array(
           'conditions'=>array('User.Userdetail.visible_status'=>'Online'), 'recursive'=>3));

我的问题:

我想找到所有DebateComment。但条件是visibale_status =>在Userdetails中在线。

3 个答案:

答案 0 :(得分:3)

$users = $this->DebateComment->User->Userdetail->find('list',array(
    'fields'=>array('user_id'),
    'conditions'=>array('Userdetail.visible_status'=>'Online')
));
$arr = $this->DebateComment->find('all',array(
    'conditions'=>array('DebateComment.user_id'=>$users)
));

您可以使用可包含或递归来获取第二个查询中的相关数据。

答案 1 :(得分:0)

很抱歉,如果是评论,但我没有看到任何选项在我的界面上评论你的问题。我认为这是JOIN的结果你在这里或其他任何人实施了BELONGSTO协会吗?你试过提到visibale_status JOIN条件下的ONLINE?它有用吗?还有另一种获取递归数据的方法。

$this->DebateComment-recursive = 3

我不确定这里的递归程度。请检查一下。

答案 2 :(得分:0)

$arr = $this->DebateComment->find('all',array('joins' => array(array('table' => 'userdetails','alias' => 'Userdetail','type' => 'INNER','foreignKey' => false,'conditions' => array('DebateComment.user_id = Userdetail.user_id','Userdetail.visible_status'=>'Online'))),
 'recursive'=> 2));