Commit ffe94018 by Angel Faryshta Guevara Committed by Qiang Xue

simplify findByCondition

parent 057828c0
...@@ -165,12 +165,11 @@ class ActiveRecord extends BaseActiveRecord ...@@ -165,12 +165,11 @@ class ActiveRecord extends BaseActiveRecord
* Finds ActiveRecord instance(s) by the given condition. * Finds ActiveRecord instance(s) by the given condition.
* This method is internally called by [[findOne()]] and [[findAll()]]. * This method is internally called by [[findOne()]] and [[findAll()]].
* @param mixed $condition please refer to [[findOne()]] for the explanation of this parameter * @param mixed $condition please refer to [[findOne()]] for the explanation of this parameter
* @param boolean $one whether this method is called by [[findOne()]] or [[findAll()]] * @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
* @return static|static[]
* @throws InvalidConfigException if there is no primary key defined * @throws InvalidConfigException if there is no primary key defined
* @internal * @internal
*/ */
protected static function findByCondition($condition, $one) protected static function findByCondition($condition)
{ {
$query = static::find(); $query = static::find();
...@@ -188,7 +187,7 @@ class ActiveRecord extends BaseActiveRecord ...@@ -188,7 +187,7 @@ class ActiveRecord extends BaseActiveRecord
} }
} }
return $one ? $query->andWhere($condition)->one() : $query->andWhere($condition)->all(); return $query->andWhere($condition);
} }
/** /**
......
...@@ -98,7 +98,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -98,7 +98,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/ */
public static function findOne($condition) public static function findOne($condition)
{ {
return static::findByCondition($condition, true); return static::findByCondition($condition)->one();
} }
/** /**
...@@ -107,19 +107,18 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -107,19 +107,18 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/ */
public static function findAll($condition) public static function findAll($condition)
{ {
return static::findByCondition($condition, false); return static::findByCondition($condition)->all();
} }
/** /**
* Finds ActiveRecord instance(s) by the given condition. * Finds ActiveRecord instance(s) by the given condition.
* This method is internally called by [[findOne()]] and [[findAll()]]. * This method is internally called by [[findOne()]] and [[findAll()]].
* @param mixed $condition please refer to [[findOne()]] for the explanation of this parameter * @param mixed $condition please refer to [[findOne()]] for the explanation of this parameter
* @param boolean $one whether this method is called by [[findOne()]] or [[findAll()]] * @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
* @return static|static[]
* @throws InvalidConfigException if there is no primary key defined * @throws InvalidConfigException if there is no primary key defined
* @internal * @internal
*/ */
protected static function findByCondition($condition, $one) protected static function findByCondition($condition)
{ {
$query = static::find(); $query = static::find();
...@@ -133,7 +132,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -133,7 +132,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
} }
} }
return $one ? $query->andWhere($condition)->one() : $query->andWhere($condition)->all(); return $query->andWhere($condition);
} }
/** /**
......
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