예제 #1
0
 /**
  * Finds ActiveRecord instance(s) by the given condition.
  * This method is internally called by [[findOne()]] and [[findAll()]].
  * @param mixed $condition please refer to [[findOne()]] for the explanation of this parameter
  * @return ActiveQueryInterface the newly created [[ActiveQueryInterface|ActiveQuery]] instance.
  * @throws InvalidConfigException if there is no primary key defined
  * @internal
  */
 protected static function findByCondition($condition)
 {
     $query = static::find();
     if (!ArrayHelper::isAssociative($condition)) {
         // query by primary key
         $primaryKey = static::primaryKey();
         if (isset($primaryKey[0])) {
             $pk = $primaryKey[0];
             if (!empty($query->join) || !empty($query->joinWith)) {
                 $pk = static::tableName() . '.' . $pk;
             }
             $condition = [$pk => $condition];
         } else {
             throw new InvalidConfigException('"' . get_called_class() . '" must have a primary key.');
         }
     }
     return $query->andWhere($condition);
 }