The UsersDetails association is not defined on Users


#1

HIi there,

I’m trying to contain the UsersDetails table in my query.
For this, I’m using the following query:

$user = $this->Users->findByEmail($this->request->getData('email'))->contain(['UsersDetails'])->first();

This, however, results in the following error:

The UsersDetails association is not defined on Users.

This is weird because when I open my UsersTable.php, I can clearly see an association.

$this->hasOne('UsersDetails', [
    'foreignKey' => 'id',
    'joinType' => 'INNER'
]);

What am I doing wrong?

UPDATE: Tried re-baking the models, according to bake, this association doesn’t exist, according to MySQL Workbench, it does.


#2

Solution: I forgot to load the model…