Insert the given attributes and set the ID on the model.

@param  \Illuminate\Database\Eloquent\Builder $query
@param  array $attributes
@return int|void
324691
protected function insertAndSetId(Builder $query, $attributes)
    {
        $id = ($binaries = $this->extractBinaries($attributes)) ?
            $query->getQuery()->insertLob($attributes, $binaries, $keyName = $this->getKeyName()) :
            $query->insertGetId($attributes, $keyName = $this->getKeyName());

        $this->setAttribute($keyName, $id);
    }
775491
public function addAttributes( $attributes = array() )
	{
		foreach( $attributes as $key => $value )
		{
			if( $key == 'class' )
			{
				if( is_string( $value ) )
					$value	= explode( " ", $value );
				if( !is_array( $value ) && !( $value instanceof ArrayIterator ) )
					throw new InvalidArgumentException( 'Class attribute must be string, array or iterator' );
				foreach( $value as $class )
					$this->addClass( $class );
				continue;
			}
			else
				$this->attributes[$key]	= $value;
		}
	}
37646
protected void addAttributes(Entity entity, Map<String, Object> attributes) {
        if (attributes != null) {
            for (Entry<String, Object> pairs : attributes.entrySet()) {
                entity.set(pairs.getKey(), pairs.getValue());
            }
        }
    }
903386
public function sqlInsert(
		$into,
		array $properties
	) {
		$insert_params = [];
		foreach ($properties as $attribute => $value) {
			$insert_params[':I' . $attribute] = $value; // name parameters after attribute
		}
		$sql = $this->queryBuilder->buildInsert($into, $properties, $insert_params);
		$query = $this->database->prepare($sql);
		$query->execute($insert_params);
		$this->addQuery($query->queryString, $insert_params);
		if ($query->rowCount() !== 1) {
			throw new Exception('sqlInsert rowCount=' . $query->rowCount());
		}
		return $this->database->lastInsertId();
	}
873768
public function setAttributes($attributes, $force = false)
    {
        if ($force) {
            $this->attributes = $attributes;
        } else {
            $this->attributes = array_merge($this->attributes, $attributes);
        }
    }
118318
public function update($id, $attributes)
    {
        $params = [];
        $setStr = "";

        foreach ($attributes as $key => $value) {
            if (!in_array($key, [
                $this->getPrimaryKey(),
                $this->timestampCreatedAt,
                $this->timestampUpdatedAt
            ])
            ) {
                $setStr .= "`" . str_replace("`", "``",
                        $key) . "` = :" . $key . ",";
                $params[':' . $key] = is_array($value) ? json_encode($value) : $value;
            }
        }

        if ($this->timestamps && !is_null($this->timestampUpdatedAt)) {
            $params[':' . $this->timestampUpdatedAt] = date('Y-m-d H:i:s');
            $setStr .= "`" . str_replace("`", "``", $this->timestampUpdatedAt) .
                "` = :" . $this->timestampUpdatedAt . ",";
        }

        $params[':id'] = $id;

        $sql = "UPDATE " . $this->getTable() . " SET " . rtrim($setStr, ',') .
            " WHERE " . $this->getPrimaryKey() . " = :id";

        try {
            $stmt = $this->db->prepare($sql);
            $this->setLastQuery($stmt->queryString, $params);

            $stmt->execute($params);
        } catch (\PDOException $e) {
            throw new DatabaseException($e->getMessage() . '<br>' . $this->getLastQuery()[0]);

        }

        return $stmt->rowCount();
    }
953870
protected function insertRecord(Query $query): void
	{
		if($this->primaryKeyType === static::PRIMARY_KEY_TYPE_INCREMENTING)
		{
			$this->columns[$this->primaryKey] = $query->insertAndGetId($this->columns, $this->primaryKey);
		}
		else
		{
			switch($this->primaryKeyType)
			{
				case static::PRIMARY_KEY_TYPE_UUID:
					$this->columns[$this->primaryKey] = UUID::v4();
					break;
				case static::PRIMARY_KEY_TYPE_CUSTOM:
					$this->columns[$this->primaryKey] = $this->generatePrimaryKey();
					break;
			}

			$query->insert($this->columns);
		}
	}
1072783
protected function addAttributesSearchConditions(\yii\db\ActiveQuery $query)
    {
        $tablePrefix = $this->getDb()->getSchema()->quoteSimpleTableName('t');
        $conditions = ['and'];
        $formats = $this->attributeFormats();
        $attributes = $this->attributes();
        $relations = $this->relations();
        $validAttributes = array_diff($attributes, array_keys($this->getErrors()));
        $attributeValues = $this->getAttributes($validAttributes);
        $formatter = Yii::$app->formatter;
        /** @var EnumCollection $enums */
        $enums = $formatter instanceof Formatter ? $formatter->getEnums() : null;
        foreach ($validAttributes as $attribute) {
            $value = $attributeValues[$attribute];
            if ($value === null || !isset($formats[$attribute])
                || ($enums !== null && !is_array($formats[$attribute]) && $enums->has($formats[$attribute]))
            ) {
                continue;
            }

            if (in_array($attribute, $relations)) {
                // only hasMany relations should be ever marked as valid attributes
                $conditions[] = $this->getRelationCondition($this->getRelation($attribute), $value);
            } else {
                $conditions[] = $this->getAttributeCondition($attribute, $value, $formats, $tablePrefix, $this->getDb());
            }
        }
        // don't clear attributes to allow rendering filled search form
        //$this->setAttributes(array_fill_keys($attributes, null));
        if ($conditions !== ['and']) {
            $query->andWhere($conditions);
        }
        return $query;
    }
134016
public function compileInsert(Builder $query, array $values)
    {
        // Essentially we will force every insert to be treated as a batch insert which
        // simply makes creating the SQL easier for us since we can utilize the same
        // basic routine regardless of an amount of records given to us to insert.
        $table = $this->wrapTable($query->from);
        if (!is_array(reset($values))) {
            $values = array($values);
        }

        $columns = $this->columnize(array_keys(reset($values)));

        // We need to build a list of parameter place-holders of values that are bound
        // to the query. Each insert should have the exact same amount of parameter
        // bindings so we can just go off the first list of values in this array.

        $rows = [];
        foreach ($values as $value) {
            $col_values = [];
            foreach ($value as $val) {
                $col_values[] = $this->parameter($val);
            }
            $rows[] = implode(',', $col_values);
        }
        $parameters = "(" . implode('), (', $rows) . ")";

        return "insert into $table ($columns) values $parameters";
    }
43376
public function toInsertSQL($attributes = array())
    {
        $sql = [];
        $this->params = [];
        
        $sql[] = sprintf('INSERT INTO %s', $this->table->getTableName());
        $keys = [];
        $values = [];
        foreach ($attributes as $key => $value) {
            $keys[] = $key;
            $values[] = '?';
            $this->addParam($value);
        }
        $sql[] = '(' . join(', ', $keys) . ')';
        $sql[] = 'VALUES (' . join(', ', $values) . ')';
        return join(' ', $sql);
    }
294002
public function queryString($query, array $attributes = [])
    {
        $query = new QueryStringQuery($query, $attributes);

        $this->append($query);

        return $this;
    }
1018265
protected function addAttributes(&$html, array $attributes)
	{
		if ( count($attributes) > 0 )
		{
			$attributes = Html::arrayToAttributes($attributes);

			$html .= ' ' . $attributes;
		}
	}
137579
public function addVoterVote(VoterInterface $voter, array $attributes, int $vote)
    {
        $currentLogIndex = \count($this->currentLog) - 1;
        $this->currentLog[$currentLogIndex]['voterDetails'][] = [
            'voter' => $voter,
            'attributes' => $attributes,
            'vote' => $vote,
        ];
    }
369883
private function buildQuery($table, $attributes = [])
    {
        if (class_exists($table)) {
            $query = $this->getQueryBuilderFromModel($table);
        } else {
            $query = $this->getQueryBuilderFromTable($table);
        }

        foreach ($attributes as $key => $value) {
            if (\is_array($value)) {
                call_user_func_array(array($query, "where"), $value);
            } elseif (is_null($value)) {
                $query->whereNull($key);
            } else {
                $query->where($key, $value);
            }
        }
        return $query;
    }
1361182
public function setAttributes(
        SimpleXMLElement $element,
        array $attributes
    ) {
        $storage = $element->attributes();
        foreach ($attributes as $key => $value) {
            if (isset($storage->{$key})) {
                $storage->{$key} = $value;
            } else {
                $element->addAttribute($key, $value);
            }
        }
    }
1193534
public function insert($table, $attributes = [])
    {
        $this->tableName = $table;
        $this->setAttributes($attributes);

        if ($this->save()) {
            return true;
        } else {
            return false;
        }
    }
260399
public function update(array $attributes = array())
    {
        if (! $this->exists) {
            return $this->newQuery()->update($attributes);
        }

        return $this->fill($attributes)->save();
    }