From a07facf434e85caf9433114b7c7a463a4f09b6c0 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Fri, 22 Nov 2013 20:47:39 -0500 Subject: [PATCH] Refactored hasMany and hasOne so that they support cross-DBMS relationship. --- framework/yii/db/ActiveRecord.php | 8 +++++--- framework/yii/redis/ActiveRecord.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/yii/db/ActiveRecord.php b/framework/yii/db/ActiveRecord.php index 3de4b2b..ffae3d8 100644 --- a/framework/yii/db/ActiveRecord.php +++ b/framework/yii/db/ActiveRecord.php @@ -475,7 +475,8 @@ class ActiveRecord extends Model */ public function hasOne($class, $link) { - return $this->createActiveRelation([ + /** @var ActiveRecord $class */ + return $class::createActiveRelation([ 'modelClass' => $class, 'primaryModel' => $this, 'link' => $link, @@ -513,7 +514,8 @@ class ActiveRecord extends Model */ public function hasMany($class, $link) { - return $this->createActiveRelation([ + /** @var ActiveRecord $class */ + return $class::createActiveRelation([ 'modelClass' => $class, 'primaryModel' => $this, 'link' => $link, @@ -528,7 +530,7 @@ class ActiveRecord extends Model * @param array $config the configuration passed to the ActiveRelation class. * @return ActiveRelation the newly created [[ActiveRelation]] instance. */ - protected function createActiveRelation($config = []) + public static function createActiveRelation($config = []) { return new ActiveRelation($config); } diff --git a/framework/yii/redis/ActiveRecord.php b/framework/yii/redis/ActiveRecord.php index f9fa3f3..46132fc 100644 --- a/framework/yii/redis/ActiveRecord.php +++ b/framework/yii/redis/ActiveRecord.php @@ -58,7 +58,7 @@ class ActiveRecord extends \yii\db\ActiveRecord /** * @inheritDoc */ - protected function createActiveRelation($config = []) + public static function createActiveRelation($config = []) { return new ActiveRelation($config); }