Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DISTINCT不使用hasMany cakephp_Php_Cakephp - Fatal编程技术网

DISTINCT不使用hasMany cakephp

DISTINCT不使用hasMany cakephp,php,cakephp,Php,Cakephp,我想在CakePHP2+中应用DISTINCT查询,它工作得很好,但当我用该模型绑定模型时,它不工作 这是我的密码,请核对一下 $this->User->bindModel( array( 'hasMany' => array( 'UserPreference' => array(

我想在CakePHP2+中应用DISTINCT查询,它工作得很好,但当我用该模型绑定模型时,它不工作

这是我的密码,请核对一下

$this->User->bindModel(
                    array(
                        'hasMany' => array(
                            'UserPreference' => array(
                                'className' => 'UserPreference',
                                'foreignKey' => 'user_id',
                                'fields' => 'UserPreference.notification_status',
                                'conditions' => array('UserPreference.notification_status' => 1),
                            )
                        )
                    )
            );
            $data = $this->User->find('all', array('conditions' => array('app_id NOT ' => '0', 'User.status' => 1), 'fields' => array('DISTINCT User.app_id')));
            pr($data); die;

就因为我曾经发生过这样的事情,我就改变了它:

$this->User->bindModel(
                    array(
                        'hasMany' => array(
                            'UserPreference' => array(
                                'className' => 'UserPreference',
                                'foreignKey' => 'user_id',
                                'fields' => 'UserPreference.notification_status',
                                'conditions' => array('UserPreference.notification_status = 1'),
                            )
                        )
                    )
            );