Browse Source

"ActiveRelationInterface" applied to Sphinx Active Record.

tags/2.0.0-beta
Klimov Paul 11 years ago
parent
commit
f228f21541
  1. 10
      extensions/sphinx/ActiveRecord.php

10
extensions/sphinx/ActiveRecord.php

@ -12,6 +12,7 @@ use yii\base\InvalidParamException;
use yii\base\Model; use yii\base\Model;
use yii\base\ModelEvent; use yii\base\ModelEvent;
use yii\base\UnknownMethodException; use yii\base\UnknownMethodException;
use yii\db\ActiveRelationInterface;
use yii\db\Expression; use yii\db\Expression;
use yii\db\StaleObjectException; use yii\db\StaleObjectException;
use yii\helpers\Inflector; use yii\helpers\Inflector;
@ -324,8 +325,7 @@ class ActiveRecord extends Model
return $this->_related[$name]; return $this->_related[$name];
} }
$value = parent::__get($name); $value = parent::__get($name);
// TODO: relation if ($value instanceof ActiveRelationInterface) {
if ($value instanceof ActiveRelation) {
return $this->_related[$name] = $value->multiple ? $value->all() : $value->one(); return $this->_related[$name] = $value->multiple ? $value->all() : $value->one();
} else { } else {
return $value; return $value;
@ -1094,10 +1094,10 @@ class ActiveRecord extends Model
/** /**
* Returns the relation object with the specified name. * Returns the relation object with the specified name.
* A relation is defined by a getter method which returns an [[ActiveRelation]] object. * A relation is defined by a getter method which returns an [[ActiveRelationInterface]] object.
* It can be declared in either the Active Record class itself or one of its behaviors. * It can be declared in either the Active Record class itself or one of its behaviors.
* @param string $name the relation name * @param string $name the relation name
* @return ActiveRelation the relation object * @return ActiveRelationInterface the relation object
* @throws InvalidParamException if the named relation does not exist. * @throws InvalidParamException if the named relation does not exist.
*/ */
public function getRelation($name) public function getRelation($name)
@ -1105,7 +1105,7 @@ class ActiveRecord extends Model
$getter = 'get' . $name; $getter = 'get' . $name;
try { try {
$relation = $this->$getter(); $relation = $this->$getter();
if ($relation instanceof ActiveRelation) { if ($relation instanceof ActiveRelationInterface) {
return $relation; return $relation;
} else { } else {
return null; return null;

Loading…
Cancel
Save