Hello I have relationship in User model Like This.
UserModel
public $hasOne = [
'Userdetail' => [
'className' => 'Userdetail',
'foreignKey' => 'user_id'
],
'Application' => [
'className' => 'Application',
'foreignKey' => 'user_id'
],
];
I have add extra HasOne Relationship in MyConroller Like below :
Controller
$this->User->bindModel([
'hasOne' => [
'Events' => [
'className' => 'Events',
'foreignKey' => 'user_id',
'dependent' => true,
]
]
]);
I am create a pagination with the User model like below :
Pagination
$this->paginate = [
'conditions' => [
$this->conditions,
'Events.id !=' => null
],
'order' => 'User.id DESC'
];
I don't want that record whose event id is null so I put this in pagination condition. Than i got below error.
Unknown column 'Events.id' in 'where clause'
Event's model is not reflect in the Count query for the pagination.
Please help me on this concern.
Thanks in advance for helping me.
You have to add false
as a second parameter in bindModel
to make the changes permanent:
$this->User->bindModel([
'hasOne' => [
'Events' => [
'className' => 'Events',
'foreignKey' => 'user_id',
'dependent' => true,
]
]
],false);
Otherwise CakePHP will revert to the previously defined relationships in the second query that produces the count, which is different from the first one that retrieves the results.