Browse Source

Merge pull request #14 from bookin/patch-1

Check Interface instead of Class
tags/1.2.0
Alban Jubert 8 years ago committed by GitHub
parent
commit
5d7dbcb390
  1. 3
      src/SaveRelationsBehavior.php

3
src/SaveRelationsBehavior.php

@ -8,6 +8,7 @@ use yii\base\Behavior;
use yii\base\Exception; use yii\base\Exception;
use yii\base\ModelEvent; use yii\base\ModelEvent;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
use yii\db\ActiveQueryInterface;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
use yii\db\Transaction; use yii\db\Transaction;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -58,7 +59,7 @@ class SaveRelationsBehavior extends Behavior
public function canSetProperty($name, $checkVars = true) public function canSetProperty($name, $checkVars = true)
{ {
$getter = 'get' . $name; $getter = 'get' . $name;
if (in_array($name, $this->relations) && method_exists($this->owner, $getter) && $this->owner->$getter() instanceof ActiveQuery) { if (in_array($name, $this->relations) && method_exists($this->owner, $getter) && $this->owner->$getter() instanceof ActiveQueryInterface) {
return true; return true;
} }
return parent::canSetProperty($name, $checkVars); return parent::canSetProperty($name, $checkVars);

Loading…
Cancel
Save