Hi all,
I have a set of functions that I use across multiple models so I created a CustomActiveRecord that extends activerecord.
The problem I am facing is that activerecord seems to handle static vs non-static calls properly in the afterFind function. But when it is in an extended class it does not. I think its probably easier to copy my code than explain.
class AssesmentNotes extends CustomActiveRecord
{
public $jsonVariables = ['notes'];
public function afterFind()
{
parent::afterFind();
foreach ($this->jsonVariables as $jsonVariable) {
$this->{$jsonVariable} = Json::decode($this->$jsonVariable);
}
return true;
}
}
The above works without issue. But when I move the afterFind function into the CustomActiveRecord, the $jsonVariables = [ânotesâ] is only set when the class is not called statically, which isnt great for calls like
AssesmentNotes::findOne( [âapp_idâ=>$this->id])
So really there are two questions:
- how to properly pass the jsonVaraiables to the parent/child class for both static and non static
- how to handle the static vs non static method call in CustomActiveRecord
Many thanks