I have Users -> hasMany -> Pupils -> hasMany -> EduHistories
I save them by associated Entity like below
$user = $this->Users->newEntity($userData, [
'associated' => ['Pupils.EduHistories']
The Pupils saved OK with a correct ID, the EduHistories is also OK with correct ID of Pupils.
However, the Pupils always has user_id = 1, even the Users is saved, with no error, and ID is something else.
I am not assigning ID manually to any of them. They all new entities.
And I check associations in Models tables, they seem to be fine.
What could possibly wrong?
Thank you for your help.
Check the contents of
$userData, and check what the
$user looks like after the
newEntity call. This will help you narrow down where that bad
user_id is coming from.
Thanks for your suggestion
I think I found my problem:
I suppose that I use PupilsTable class (getting from UsersTables class) to link with Courses Table class, but, somehow CakePHP links the Users with Courses. Please confirm if I am right, the code is below:
Once we get the Table class from association, it’s NOT only getting the reference of the object right?
Thank you very much