I try to self join my table user to get parent-child associations but it didn't work
here is my association in the Users model:
$this->belongsToMany('Parents', [
'className' => 'Users',
'joinTable' => 'users_users',
'foreignKey' => 'id',
'targetForeignKey' => 'parent_id'
]);
$this->belongsToMany('Childs', [
'className' => 'Users',
'joinTable' => 'users_users',
'foreignKey' => 'id',
'targetForeignKey' => 'child_id'
]);
I didn't make parameters in the UsersUsers model.
When I do:
$test = $this->Users->find()->where(['id =' => 65])->contain(['Parents']);
I get the child entity but the parents property is empty so I do something wrong but I don't know what.
Thanks for your help :)
My foreignKeys were bad, that was like this:
Problem solved