All associated entities saved, but master entity ID always = 1 in it's child entity

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[0] saved OK with a correct ID, the EduHistories[0] is also OK with correct ID of Pupils[0].
However, the Pupils[0] 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:

$this->Users->Pupils->link($course, [$user->pupils[0]]);

Once we get the Table class from association, it’s NOT only getting the reference of the object right?

Thank you very much