I have 2 entites: ActivityParameter and Activity and some logic:
Activity entity has relationship:
$this->hasMany('id', 'ActivityParameter', 'activity_id', [
'alias' => 'parameters',
'reusable' => true,
'foreignKey' => [
'action' => Relation::ACTION_CASCADE
]
]);
Logic:
$parameter = new ActivityParameter();
$parameter->setValue(10.101);
$parameter->setUnitId(1);
$activity = new Activity();
$activity->parameters = $parameter;
My problem is that:
count($activity->parameters);
gives 1, but:
count($activity->getParameters());
gives 0.
How to resolve this problem? I need to use getParameters() beacause later I use:
$activity->getParameters("value = '10.101'");
I found it is needed to make $activity->save(); to use $activity->getParameters(). I don't want to save these objectd because it's unit test. How to fix it?