Answer the question
In order to leave comments, you need to log in
How to correctly use rules in Yii2 in behaviors and is it possible to use a relationship getter there?
Good afternoon
Regarding the first question - if yes, then it is correct like this:
public function rules() {
return [];
}
public function rules() {
return array_merger($this->owner::rules,[]);
}
public function getRating()
{
$className = $this->className;
return $this->hasMany($className::className(), [$this->attribute => 'id']);
}
Answer the question
In order to leave comments, you need to log in
about rules:
https://stackoverflow.com/questions/42510332/yii2-...
about links:
yes you can, but your example is not working. $className first already contains the name of the class, and the second time you try to pull the method already at the string.
Here is an example of a behavior that works with links:
https://github.com/la-haute-societe/yii2-save-rela...
Perhaps in your case it is more convenient to use a trait rather than a behavior?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question