Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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
CakePHP分页计数查询不工作_Php_Pagination_Cakephp 2.0_Cakephp 2.6 - Fatal编程技术网

CakePHP分页计数查询不工作

CakePHP分页计数查询不工作,php,pagination,cakephp-2.0,cakephp-2.6,Php,Pagination,Cakephp 2.0,Cakephp 2.6,你好,我在用户模型中有这样的关系 用户模型 public $hasOne = [ 'Userdetail' => [ 'className' => 'Userdetail', 'foreignKey' => 'user_id' ], 'Application' => [ 'className' => 'Application',

你好,我在用户模型中有这样的关系

用户模型

public $hasOne = [
        'Userdetail'  => [
            'className'    => 'Userdetail',
            'foreignKey'   => 'user_id'
        ],
        'Application' => [
            'className'    => 'Application',
            'foreignKey'   => 'user_id'
        ],
    ];
我在MyConroller中添加了额外的HasOne关系,如下所示:

控制器

$this->User->bindModel([
            'hasOne' => [
                'Events' => [
                    'className'  => 'Events',
                    'foreignKey' => 'user_id',
                    'dependent' => true,
                ]
            ]
        ]);
我正在使用如下用户模型创建分页:

分页

$this->paginate = [
            'conditions' => [
                $this->conditions,
                'Events.id !=' => null
            ],
            'order' => 'User.id DESC'
        ];
我不想要那个事件id为null的记录,所以我把它放在分页条件下。比我得到以下的错误

Unknown column 'Events.id' in 'where clause'
事件的模型未反映在分页的计数查询中

请帮我解决这个问题


提前感谢您的帮助。

您必须在
bindModel
中添加
false
作为第二个参数,以使更改永久化:

$this->User->bindModel([
        'hasOne' => [
            'Events' => [
                'className'  => 'Events',
                'foreignKey' => 'user_id',
                'dependent' => true,
            ]
        ]
    ],false);
否则,CakePHP将在生成计数的第二个查询中恢复到先前定义的关系,这与检索结果的第一个查询不同


请参见您必须在
bindModel
中添加
false
作为第二个参数,以使更改永久化:

$this->User->bindModel([
        'hasOne' => [
            'Events' => [
                'className'  => 'Events',
                'foreignKey' => 'user_id',
                'dependent' => true,
            ]
        ]
    ],false);
否则,CakePHP将在生成计数的第二个查询中恢复到先前定义的关系,这与检索结果的第一个查询不同


请参见

$this->User->bindModel(['hasOne'=>['Event'=>['className'=>'Events','foreignKey'=>'User\u id','dependent'=>true,],'conditions'=>['Events.id!='=>null,]])
并将其从
分页条件中删除
不,它是CakePhp 2.6我尝试了这个@Anant,但它不起作用很抱歉出现了一个错误
'className'=>'Event'
'conditions'=>['Event.id!='
是的,它正在工作,但它将检索事件表中没有任何条目的所有数据。我不希望那些记录没有任何事件的数据。
$this->User->bindModel(['hasOne'=>['Event'=>['className'=>'events','foreignKey'=>'User\u id','dependent'=>true','conditions'=>['Events.id!='=>null,]]];
并将其从
paginate条件中删除
不,它是CakePhp 2.6I尝试了这个@Anant,但它不起作用。很抱歉,有一个错误
'className'=>'Event'
'conditions'=>['Event.id!='
是,它正在工作,但它将检索事件表中没有任何条目的所有数据。我不希望记录没有任何事件的数据。