I’m in the midst of rewriting code that was originally written for Cake 2.3. I’ve successfully moved over a few plugins to Cake3.6 but am stuck with an events plugin that has associated tables EventOccurrences and EventActivities and EventLocations
An event can have multiple occurrences (ie the same event can take place multiple times, in multiple locations - it has one EventActivity type)
In Cake 2 (the code wasn’t in a plugin) I had
class Event extends AppModel {
public $hasMany = array(
'EventOccurrence' => array(
'dependent' => true,
'order' => 'EventOccurrence.start_date'
)
);
public $belongsTo = array(
'EventActivity' => array('counterCache' => 'counter'),
);
…
and
class EventLocation extends AppModel {
public $hasMany = array(
'EventOccurrence',
);
}
…
and
class EventOccurrence extends AppModel {
public $belongsTo = array(
'Event',
'EventLocation',
);
With Cake 3 I’ve, so far, got EventOccurrencesTable.php and EventsTable.php with
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class EventOccurrencesTable extends Table {
public function initialize(array $config)
{
$this->setTable('EventOccurrences');
$this->belongsTo('Events', ['className' => 'Events.Events','foreignKey' => 'event_id', 'joinType' => 'LEFT']);
}
}
and
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class EventsTable extends Table {
public function initialize(array $config)
{
$this->setTable('Events');
$this->hasMany('EventOccurrences', ['className' => 'Events.EventOccurrences',
'foreignKey' => 'event_id',
'joinType' => 'LEFT',
'dependent' => true]);
}
}
respectively
I’ve tried lots of find calls with contain in the events controller but alway get “The EventOccurrences association is not defined on Events.”
Any idea? Thanks for your time