I’m having problems with an association CakePHP 2.9.1, I wonder if someone should point me in the right direction, the code is running from a plugin, the data is selected but the array returned only contains data for the current model “OnCallteam”, the other model is there in the array but it’s empty and a warning is issued to the console.
Model “Oncallteam” is not associated with model “Oncallteam” in [/usr/share/XXXXX/lib/Cake/Model/Behavior/ContainableBehavior.php,
I don’t know why I’m being issued this warning because the model I’m calling from is Oncallteam so don’t understand why it’s having an issue calling itself. (I’ve had to change the naming to remove the company name from the post)
Here is my model (I’ve removed
class Oncallteam extends SchedulerModuleAppModel
// Oncall structure ----> Group --> Team --> booking public $useTable = 'oncallteams'; public $hasAndBelongsToMany = [ 'Tenant' => [ 'className' => 'Tenant', 'joinTable' => 'oncallteams_to_tenants', 'unique' => true, 'dependent' => false, // We don't want to delete the Service Template by mistake! ] ]; public $hasMany = [ 'Oncallbooking' => [ 'className' => 'SchedulerModule.GeOncallbooking', 'foreignKey' => 'oncall_team_id', 'dependent' => true, ], ]; public $belongsTo = [ 'GeOncallgroup' => [ 'className' => 'SchedulerModule.GeOncallgroup', 'foreignKey' => 'oncall_group_id' ] ];
Here is the function, it’s inside this model, I want to get engineers with a booking before 26 April 2017 (in model Oncallbooking), and a team id of 25 (in this model):
$result = $this->find("all", [ 'contain' => [ 'Oncallbooking' => [ 'conditions' => [ 'Oncallbooking.from' => '< 2017-04-26' ], 'fields' => [ 'Oncallbooking.*' ], ], 'Oncallteam' => [ 'conditions' => [ 'Oncallteam.id' => 25 ] ], ], 'fields' => [ 'Oncallteam.*', ], ]);
Thanks in advance for any help and sorry if I’ve done something stupid.