Will check if Active Record is unique by exists query.
@param array $attributes
@return boolean
491956
private function isActiveRecordUnique($attributes) {
        /* @var $class \yii\db\ActiveRecord */
        $class = $this->className;
        return empty($attributes) ? true :
                !$class::find()->where($attributes)->exists();
    }
629019
public function isHashed($attribute)
    {
        if ( ! array_key_exists($attribute, $this->attributes)) {
            return false;
        }

        $info = password_get_info($this->attributes[$attribute]);

        return (bool) ($info['algo'] !== 0);
    }
1140691
public function create(array $attributes)
	{
		$foreign = $this->getForeignAttributesForCreate();

		// When saving a polymorphic relationship, we need to set not only the foreign
		// key, but also the foreign key type, which is typically the class name of
		// the parent model. This makes the polymorphic item unique in the table.
		$attributes = array_merge($attributes, $foreign);

		$instance = $this->related->newInstance($attributes);

		$instance->save();

		return $instance;
	}
1195027
protected function contains(array $attributes = array())
    {
        $collection = $this->findAll();
        $filtered   = $collection->filter(function($value, $key) use($attributes) {
            foreach ($attributes as $keyname => $attrVal) {
                if ($value->{$keyname} != $attrVal) {
                    return false;
                }
            }
            return true;
        });
        return $filtered->count() > 0;
    }
1018284
public function create($attributes = array())
    {
        $entity = $this->build($attributes);
        $cond = $this->condition();

        // to SQL.
        $sql = $cond->toInsertSQL($attributes);
        var_dump($sql, $cond->getParams());

        // query.
        $sth = $this->query($sql, $cond->getParams());
        if ( $sth->isSuccess() ) {
            $entity->exists = true;
            $entity->setPrimaryValue($sth->lastInsertId());
            return $entity;
        }
    }
746120
public function isGranted($attributes, $object = null)
    {
        if ( ! is_array($attributes)) {
            $attributes = [$attributes];
        }

        return $this->authorizationManager->decide($this->getToken(), $attributes, $object);
    }
882208
private function applyAttributes($attributes)
    {
        if (array_key_exists('count', $attributes) && $attributes['count'] > 0) {
            $keys = array_keys($attributes);

            foreach ($keys as $key) {
                if (is_array($attributes[$key]) && array_key_exists(0, $attributes[$key])) {
                    // If the entry has multiple attributes, we'll make sure we loop through each one
                    if (array_key_exists('count', $attributes[$key]) && $attributes[$key]['count'] > 1) {
                        $data = [];

                        for ($i = 0; $i <= $attributes[$key]['count']; $i++) {
                            $data[] = $attributes[$key][$i];
                        }

                        $this->setAttribute($key, array_filter($data));
                    } else {
                        // Looks like only one attribute exists, let's set it
                        $this->setAttribute($key, $attributes[$key][0]);
                    }
                }
            }

            $this->applyExtraAttributes();
        }
    }
1085443
public function updateOne(array $attributes)
    {
        $updated = $this->update(Arr::except($attributes, ['author_id']));

        $this->tags()->sync($attributes['tags']);

        $seoAttributes = static::extractSeoAttributes($attributes);

        $this->hasSeo() ? $this->updateSeo($seoAttributes) : $this->createSeo($seoAttributes);

        return $updated;
    }
325559
public function replicate(array $attributes = [])
    {
        if (!isset($attributes['query'])) {
            return new static(array_merge($this->toArray(), $attributes));
        }

        $queryAttributes = $attributes['query'];
        unset($attributes['query']);

        $newAttributes = array_merge($this->toArray(), $attributes);

        $newAttributes['query'] = $this->mergeOrReplaceQuery($queryAttributes);

        return new static($newAttributes);
    }
674237
public function first(array $attributes = null)
    {
        $query = $this->eagerLoadRelations();

        if (!is_null($attributes)) {
            $query = $query->where($attributes);
        }

        return $query->first();
    }
770565
public function exists( $key ) {
		return ! collect( is_array( $key ) ? $key : func_get_args() )->contains(
			function ( $key ) {
				return ! Arr::exists( $this->attributes, $key );
			}
		);
	}
442832
public function uniqueForEntity($attribute, $params)
    {
        $translationsIds = ProductTranslation::find()
            ->asArray()->where(['product_id' => $this->product_id])->select('id')->all();

        $seoUrl = SeoData::find()
            ->where(['entity_name' => ProductTranslation::className(), 'seo_url' => $this->seoUrl])
            ->andWhere(['not in', 'entity_id', ArrayHelper::getColumn($translationsIds, 'id')])
            ->one();

        if (!empty($seoUrl)) {
            $this->addError($attribute, \Yii::t('shop', 'Such url already exists'));
        }
    }
804212
public function was_changed( $attributes = null ) {
		return $this->has_changes(
			$this->get_changes(), is_array( $attributes ) ? $attributes : func_get_args()
		);
	}
1191920
public function isUnique(array $keys)
    {
        if (1 === count($keys)) {
            $column = $keys[0] instanceof Column ? $keys[0] : $this->getColumn($keys[0]);
            if ($column) {
                if ($column->isUnique()) {
                    return true;
                }

                if ($column->isPrimaryKey() && 1 === count($column->getTable()->getPrimaryKey())) {
                    return true;
                }
            }
        }

        // check if pk == $keys
        if (count($this->getPrimaryKey()) === count($keys)) {
            $allPk = true;
            $stringArray = is_string($keys[0]);
            foreach ($this->getPrimaryKey() as $pk) {
                if ($stringArray) {
                    if (!in_array($pk->getName(), $keys)) {
                        $allPk = false;
                        break;
                    }
                } else {
                    if (!in_array($pk, $keys)) {
                        $allPk = false;
                        break;
                    }
                }
            }

            if ($allPk) {
                return true;
            }
        }

        // check if there is a unique constrains that contains exactly the $keys
        if ($this->unices) {
            foreach ($this->unices as $unique) {
                if (count($unique->getColumns()) === count($keys)) {
                    $allAvailable = true;
                    foreach ($keys as $key) {
                        if (!$unique->hasColumn($key instanceof Column ? $key->getName() : $key)) {
                            $allAvailable = false;
                            break;
                        }
                    }
                    if ($allAvailable) {
                        return true;
                    }
                } else {
                    continue;
                }
            }
        }

        return false;
    }
497279
public function user(array $attributes = [])
    {
        $model = $this->schema->userModel();

        return (new $model($attributes, $this->query))
            ->setAttribute($this->schema->objectClass(), $this->schema->userObjectClasses());
    }
225426
public function replace(array $attributes):bool
    {
        $status = false;
        foreach ($this->session as $one => $value) {
            if (null !== $this->get($one)) {
                $this->set($one, $value);
                $status = true;
            }
        }
        if (true === $status) {
            $this->save();
        }

        return ($status);
    }
1141145
public function validateExists($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'exists');

        [$connection, $table] = $this->parseTable($parameters[0]);

        // The second parameter position holds the name of the column that should be
        // verified as existing. If this parameter is not specified we will guess
        // that the columns being "verified" shares the given attribute's name.
        $column = $this->getQueryColumn($parameters, $attribute);

        $expected = is_array($value) ? count(array_unique($value)) : 1;

        return $this->getExistCount(
            $connection, $table, $column, $value, $parameters
        ) >= $expected;
    }