Commit a07facf4 by Qiang Xue

Refactored hasMany and hasOne so that they support cross-DBMS relationship.

parent a95d54cc
...@@ -475,7 +475,8 @@ class ActiveRecord extends Model ...@@ -475,7 +475,8 @@ class ActiveRecord extends Model
*/ */
public function hasOne($class, $link) public function hasOne($class, $link)
{ {
return $this->createActiveRelation([ /** @var ActiveRecord $class */
return $class::createActiveRelation([
'modelClass' => $class, 'modelClass' => $class,
'primaryModel' => $this, 'primaryModel' => $this,
'link' => $link, 'link' => $link,
...@@ -513,7 +514,8 @@ class ActiveRecord extends Model ...@@ -513,7 +514,8 @@ class ActiveRecord extends Model
*/ */
public function hasMany($class, $link) public function hasMany($class, $link)
{ {
return $this->createActiveRelation([ /** @var ActiveRecord $class */
return $class::createActiveRelation([
'modelClass' => $class, 'modelClass' => $class,
'primaryModel' => $this, 'primaryModel' => $this,
'link' => $link, 'link' => $link,
...@@ -528,7 +530,7 @@ class ActiveRecord extends Model ...@@ -528,7 +530,7 @@ class ActiveRecord extends Model
* @param array $config the configuration passed to the ActiveRelation class. * @param array $config the configuration passed to the ActiveRelation class.
* @return ActiveRelation the newly created [[ActiveRelation]] instance. * @return ActiveRelation the newly created [[ActiveRelation]] instance.
*/ */
protected function createActiveRelation($config = []) public static function createActiveRelation($config = [])
{ {
return new ActiveRelation($config); return new ActiveRelation($config);
} }
......
...@@ -58,7 +58,7 @@ class ActiveRecord extends \yii\db\ActiveRecord ...@@ -58,7 +58,7 @@ class ActiveRecord extends \yii\db\ActiveRecord
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function createActiveRelation($config = []) public static function createActiveRelation($config = [])
{ {
return new ActiveRelation($config); return new ActiveRelation($config);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment