I’m using CakePHP 4 and using bake function. When I save the record from table contacts without user_id it will save the record but not listed in the index. However, if I save contacts record with user_id, it will display the record in the index. I believe it is caused by the paginate->contain in contacts controller. However, when I removed the code, it will produce an error.
public function index()
{
$this->paginate = [
'contain' => ['Users'],
];
$contacts = $this->paginate($this->Contacts);
$this->set(compact('contacts'));
}
I tried to remove this code from the model, and it also produces an error
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->existsIn(['user_id'], 'Users'));
return $rules;
}
How can I list all the record with or without user_id in contacts index? Thank you.