I have a plugin which contains all the tables it uses.
plugins
/MyPlugin
/src
/Model
/Table
EventsTable.php
EventValuesTable.php
...
I am trying to save an Event
entity and its related hasMany EventValues
association.
$data = [
'event_type_id' => 5,
'event_values' => $values // An array of EventValue entities
];
$event = $eventsTable->newEntity($data, [
'associated' => ['MyPlugin.EventValues']
]);
However, it cannot find the associated table and gives the following error:
Cannot marshal data for "MyPlugin" association. It is not associated with "Events"
Now I have spent hours debugging this, and here is where I am so far:
The exception is thrown from a new piece of code introduced to the Cake core in version 3.3
The exception is thrown from \Cake\ORM\Marshaller.php (Line 94) when it's trying to break down the
associated
array.
The Problem:
The Marshaller
class seems to be treating the MyPlugin.EventValues
association as a nested model association - i.e. It thinks MyPlugin
is the name of a model related to the main entity being saved (Event
). It's not looking for the model in my plugin's src/Table
directory.
I need to find a way to get Cake to realise that MyPlugin.EventValues
means:
plugins/MyPlugin/src/Model/Table/EventValuesTable.php
Instead, it's analysing it as:
src/Model/Table/MyPluginsTable.php
So my question is:
- Is this a Cake bug which has been introduced?
- If not, how can I tell it to make the association from my plugin tables?
I know the first thing you guys will ask is to see my model associations and everything, BUT this was working before updating from Cake 3.1 to 3.3, and I am 100% sure the associations are correct. Remember all the tables are in the plugin table directory, nothing is from the main app table directory.