diff --git a/extensions/sphinx/ActiveRecord.php b/extensions/sphinx/ActiveRecord.php index 08617b4..690a59d 100644 --- a/extensions/sphinx/ActiveRecord.php +++ b/extensions/sphinx/ActiveRecord.php @@ -1126,4 +1126,27 @@ class ActiveRecord extends Model $transactions = $this->transactions(); return isset($transactions[$scenario]) && ($transactions[$scenario] & $operation); } + + /** + * Sets the element at the specified offset. + * This method is required by the SPL interface `ArrayAccess`. + * It is implicitly called when you use something like `$model[$offset] = $item;`. + * @param integer $offset the offset to set element + * @param mixed $item the element value + * @throws \Exception on failure + */ + public function offsetSet($offset, $item) + { + // Bypass relation owner restriction to 'yii\db\ActiveRecord' at [[ActiveRelationTrait::findWith()]]: + try { + $relation = $this->getRelation($offset); + if (is_object($relation)) { + $this->populateRelation($offset, $item); + return; + } + } catch (UnknownMethodException $e) { + throw $e->getPrevious(); + } + parent::offsetSet($offset, $item); + } } \ No newline at end of file diff --git a/tests/unit/data/sphinx/ar/ArticleDb.php b/tests/unit/data/sphinx/ar/ArticleDb.php index de9ca0f..3c32f99 100644 --- a/tests/unit/data/sphinx/ar/ArticleDb.php +++ b/tests/unit/data/sphinx/ar/ArticleDb.php @@ -2,9 +2,9 @@ namespace yiiunit\data\sphinx\ar; -use yiiunit\data\ar; +use yiiunit\data\ar\ActiveRecord as ActiveRecordDb; -class ArticleDb extends ActiveRecord +class ArticleDb extends ActiveRecordDb { public static function tableName() { diff --git a/tests/unit/data/sphinx/ar/ItemDb.php b/tests/unit/data/sphinx/ar/ItemDb.php index 128e473..ddf7eea 100644 --- a/tests/unit/data/sphinx/ar/ItemDb.php +++ b/tests/unit/data/sphinx/ar/ItemDb.php @@ -2,9 +2,9 @@ namespace yiiunit\data\sphinx\ar; -use yiiunit\data\ar; +use yiiunit\data\ar\ActiveRecord as ActiveRecordDb; -class ItemDb extends ActiveRecord +class ItemDb extends ActiveRecordDb { public static function tableName() {