I saw several threads here with the same question but no one helped me.
I try to save data in an object with jointable.
First object is a worker
And the worker has many PLZ
$this->belongsToMany('PLZ', [
'foreignKey' => 'worker_id',
'targetForeignKey' => 'plz_id',
'joinTable' => 'workers_plz',
'dependent' => true
]);
There is a table plzTable wich contains plz_id and plz_no
When I try to create a worker, I will search for the plz_id in the plzTable.
This works fine.
But when I try to fill in the plz_id in the worker object, I receive an error.
worker->PLZ->id = $plz->id;
Errormessage:
Attempt to assign property “id” on null
But the worker object is not null and when I check the accessibility the the PLZ is true.
I am really not sure how cakephp saves data in a join table.
Maybe someone can help