Save the objects in the database

It updates the objects in the DB. It also cleans up the cache so it will be refreshed next time they are used

@return null
352096
public function saveObjects()
    {
        $post = Yii::$app->request->post();
        $model = $this->owner;
        $url_components = explode("\\", get_class($model));
        $model_name = $url_components[2];

        if(isset($post['Object'])) {
            foreach($post['Object'] as $name => $content) {
                $object = Object::find()->where('Model = :Model and Model_id = :Model_id and name = :name', [':Model'=>$model_name, ':Model_id'=>$model->id, ':name'=>$name])->one();
                if(!$object) {
                    $object = new Object;
                    $object->name = $name;
                    $object->Model = $model_name;
                    $object->Model_id = $model->id;
                }
                $object->content = $content;
                $object->save();
            }
        }
        Yii::$app->cache->delete(get_class($this->owner) . $this->owner->id);
    }
321877
public function save()
    {
        $sQuery = $this->_prepare();

        if (preg_match('/INSERT INTO/i', $sQuery)) {

            $oDb = self::connect();

            if (!$oDb->exec($sQuery)) {
                error_log($sQuery."\n".print_r($oDb->errorInfo(), true));
            }

            $this->flush();
            return $oDb->lastInsertId();
        }
        else {

            $this->flush();

            if ($this->_mWhere instanceof Where) { $this->_mWhere->flush(); }

            return self::connect()->exec($sQuery);
        }

    }
1228868
public function save()
    {
        foreach ($this->getChanged() as $relation) {
            $this->sync($relation, $this->values->get($relation), $this->delete);
        }
    }
146474
public static function save()
    {
        try {
            $tableName = self::getTableName();
            $affectedRows = 0;
            $conn = self::getConnection();

            if(array_key_exists("id", self::$fields)){
                //update an existing record
                $sql = self::makeUpdateSQL();
            }
            else {
                //insert a new record
                $tableColumns = implode(", ", array_keys(self::$fields));
                $columnValues = "'".implode("', '", array_values(self::$fields))."'";
                $sql = "INSERT INTO ".$tableName."($tableColumns) VALUES($columnValues)";
            }

            $affectedRows = $conn->exec($sql);

            return $affectedRows;
        }
        catch(PDOException $pe) {
            return $pe->getMessage();
        }
        catch(Exception $e) {
            return $e->getMessage();
        }
    }
833845
public function save()
    {
        $collectionName = $this->intermediateCollection;

        $existingIds = [];
        $firstEntityId = $this->getParentEntity()->id;
        foreach ($this->getValue() as $item) {
            if ($item instanceof AbstractEntity && !$item->exists()) {
                $item->save();
            }

            if ($item instanceof AbstractEntity) {
                $secondEntityId = $item->id;
            } else {
                $secondEntityId = $item;
            }

            $existingIds[] = $secondEntityId;

            $data = [
                $this->thisField => $firstEntityId,
                $this->refField  => $secondEntityId
            ];

            try {
                Entity::getInstance()->getDatabase()->insertOne($collectionName, $this->arr($data)->sortKey()->val());
            } catch (BulkWriteException $e) {
                // Unique index was hit and an exception is thrown - that's ok, means the values are already inserted
                continue;
            }
        }

        /**
         * Remove old links
         */
        $removeQuery = [
            $this->thisField => $firstEntityId,
            $this->refField  => [
                '$nin' => $existingIds
            ]
        ];
        Entity::getInstance()->getDatabase()->delete($collectionName, $removeQuery);

        /**
         * The value of many2many attribute must be set to 'null' to trigger data reload on next access.
         * If this is not done, we may not have proper links between the 2 entities and it may seem as if data was missing.
         */
        $this->setValue(null);
    }
883558
public function save()
    {
        $di = DI::getDefault();

        $database = $di->getService( "database" );

        /**
         * Decide if we should update or insert
         * (if we know the record exists in the database...)
         */
        if ( $this->_exists_in_db )
        {
            /**
             * Retrieve a query from the query builder
             */
            $query = $database->buildQuery( $this->_table_name, "update", array("columns" => $this->_columns) );
            
            /**
             * Create an array with the model attributes (binding parameters)
             */
            $attributes = $this->getAttributes();
            
            /**
             * Add "snap_" prefix to the snapshot in order to not get index conflict when we merge attributes and snapshot
             */
            $snapshot = array();
            
            foreach ( $this->_snapshot as $key => $value )
            {
                $snapshot["snap_" . $key] = $value;
            }
            
            /**
             * Merge our binding parameters.
             * Bind the parameters to the query and return the result.
             */
            return $query->execute( array_merge($attributes, $snapshot) );
        }
        else
        {
            /**
             * Retrieve a query from the query builder
             */
            $query = $database->buildQuery( $this->_table_name, "insert", array("columns" => $this->_columns) );
            
            /**
             * Create an array with the model attributes (binding parameters)
             */
            $attributes = $this->getAttributes();
            
            /**
             * Bind the parameters and return the result
             */
            return $query->execute( $attributes );
        }
    }
999990
public function save()
	{
		$this->db->begin();
		foreach($this->data as $item)
		{
			$this->db->insert($this->tableName,$item);
		}
		$this->db->commit();
		return true;
	}
1087405
public function persist()
    {
        if (!$this->wasModified()) {
            return false;
        }

        foreach ($this->getModifiedData() as $id=>$data) {
            $this->writeToDB($id, $data);
        }

        if ($unsettedKeys = $this->getUnsettedKeys()) {
            $this->deleteFromDB($unsettedKeys);
        }

        $this->_originalAttributes = $this->_attributes;

        return true;
    }
1082601
public function save()
    {
        global $wpdb;

        // Get the model's properties
        $props = $this->properties();

        // Flatten complex objects
        $props = $this->flatten_props($props);

        // Insert or update?
        if (is_null($props[static::get_primary_key()])) {
            $wpdb->insert($this->get_table(), $props);

            $this->{static::get_primary_key()} = $wpdb->insert_id;
        } else {
            $wpdb->update(static::get_table(), $props, array(static::get_primary_key() => $this->{static::get_primary_key()}));
        }

        return $this->id;
    }
700763
public function save()
    {

        $con = Propel::getWriteConnection(RecordTableMap::DATABASE_NAME);
        $con->beginTransaction();

        foreach ($this->recordsPerPlayer as $record) {
            $record->save();
        }

        $con->commit();

        RecordTableMap::clearInstancePool();
    }
747591
public function save()
    {
        $model = $this->unwrap();
        $modelRelations = Cache::all($model);

        foreach ($modelRelations as $key => $mr) {
            $relation = Rel::make($mr['relation']);

            if ($relation->canSaveBefore()) {
                $relation->saveBefore($mr['child']);
            }
        }
        $model->save();

        foreach ($modelRelations as $key => $model) {
            $relation = Rel::make($mr['relation']);

            if ($relation->canSaveAfter()) {
                $relation->saveAfter($mr['child']);
            }
        }
    }
791681
private function persist()
    {
        $sessionBag = $this->session->getBag($this->getSessionBagKey());
        $sessionBag->set($this->getScope(), $this->filterAttributes());

        $databaseSessionBag = $this->session->getBag($this->getDatabaseSessionBagKey());
        $databaseSessionBag->set($this->getScope(), $this->filterAttributes(true));
    }
767006
public function save() {
    if ($this->id != self::NO_CACHE) {
      $cache = ObjectFactory::getInstance('staticCache');
      $cache->put(self::getCacheSection($this->type), self::getCacheId($this->id), $this);
    }
  }
1043002
public function save()
    {
        $data = $this->getData();
        if (!$this->currentId)
        {
            $config = $this->config();
            $config->last_id++;

            $this->setField('id', $config->last_id);
            array_push($data, $this->set);

            Helpers\Config::table($this->name)->put($config);
        }
        else
        {
            $this->setField('id', $this->currentId);
            $data[$this->currentKey] = $this->set;
        }

        Helpers\Data::table($this->name)->put($data);

//         $this->setFields();
    }
408245
public function save($object)
    {
        $this->assertObjectInstance($object);

        $state = $this->getState($object);
        if ($state->isReadOnly()) {
            return null;
        }

        $relationsIterator = new \ArrayIterator($this->getRelations());

        $modifiedManyManyRelations = $this->handleManyManyRelations($state, $relationsIterator);
        $this->handleHasManyRelations($state, $relationsIterator);
        $this->handleHasOneRelations($state, $relationsIterator);

        switch ($state->getObjectState()) {
            case EntityState::STATE_NEW:
                $primaryKey = $this->insert($object);
                break;

            case EntityState::STATE_NEW_WITH_PRIMARY_KEY:
                $pkField    = $this->getPrimaryKey();
                $primaryKey = $state->getOriginalFieldData($pkField);

                //Check if the record exists in the database
                if ($this->exists($primaryKey)) {
                    //We may have no way of knowing what has changed, but assume that the primary key hasn't
                    //Let's assume that the original data is actually all new
                    $data = $this->toArray($object);

                    //But only update the primary key if it really has changed
                    if ($data[ $pkField ] === $primaryKey) {
                        unset($data[ $pkField ]);
                    }

                    $primaryKey = $this->update($object, $data);
                } else {
                    $primaryKey = $this->insert($object);
                }
                break;

            default:
                $data       = $state->getChangedFields();
                $primaryKey = $this->update($object, $data);
                break;
        }

        $state->setState(EntityState::STATE_HANDLED);
        $state->refreshOriginalData();

        $this->updateManyToManyRelations($modifiedManyManyRelations, $primaryKey);

        return $primaryKey;
    }
55690
private function update ()
	{
		$this->before_update();

		$statement = 'UPDATE ' . static::$table_name . ' SET ';

		$sets = [];
		$values = [];

		foreach ($this->storage as $key => $value) {
			if ($value !== null) {
				$sets[] = $this->db->quote_column($key) . ' = ?';
				$values[] = $value;
			}
		}

		$statement .= implode(', ', $sets);

		$pk = $this->primary_key_condition();

		$statement .= ' WHERE ' . $pk->statement;

		$values = array_merge($values, $pk->values->getArrayCopy());

		$result = $this->db->query($statement, $values, 'multi', null, false);

		$this->stored = true;
		$this->updated = false;

		$this->after_update();

		return true;
	}
102241
public function save()
    {
        $this->hook('beforeSave', array($this->id));

        $is_update = $this->loaded();
        if ($is_update) {
            $source = array();
            foreach ($this->dirty as $name => $junk) {
                $source[$name] = $this->get($name);
            }

            // No save needed, nothing was changed
            if (empty($source)) {
                return $this;
            }

            $this->hook('beforeUpdate', array(&$source));
        } else {

            // Collect all data of a new record
            $source = $this->get();

            $this->hook('beforeInsert', array(&$source));
        }

        if ($this->controller) {
            $this->id = $this->controller->save($this, $this->id, $source);
        }

        if ($is_update) {
            $this->hook('afterUpdate');
        } else {
            $this->hook('afterInsert');
        }

        if ($this->loaded()) {
            $this->dirty = array();
            $this->hook('afterSave', array($this->id));
        }

        return $this;
    }