Save object

@param Storable $model
@param AbstractModel $parent
@return Storable
354296
public function save(Storable $model, AbstractModel $parent = null)
    {
        $response = $this->request(
            $this->buildUrl($model, $parent), $model->getId() > 0 ? 'PUT' : 'POST', $this->mapper->mapToStorage($model)
        );

        return $this->mapper->mapFromStorage($response);
    }
116657
public function save()
	{
		// Bind the rules as appropriate.
		if (is_array($this->get('rules')))
		{
			$this->set('rules', json_encode($this->get('rules')));
		}

		return parent::save();
	}
1276741
public function save(Driver $driver, ModelInterface $model)
    {
        $this->managerFactory->setModelClass(get_class($model));
        $manager = $this->managerFactory->getManager($driver);
        $preSaveEvent = new FilterModelEvent();
        $preSaveEvent->setModel($model);
        $preSaveEvent->setManager($manager);
        $this->eventSubscriber->subscribe(Constants::PRE_SAVE, $preSaveEvent);

        try {
            $manager->save($preSaveEvent->getModel());

            $postSaveEvent = new FilterModelEvent();
            $postSaveEvent->setManager($manager);
            $postSaveEvent->setModel($model);
            $this->eventSubscriber->subscribe(Constants::POST_SAVE, $postSaveEvent);
        } catch (\Exception $exception) {
            $this->errorMessage = 'message.save_failed';

            return false;
        }

        return true;
    }
588105
private function saveThroughPhalconModel(Model $model, $transaction = null) {
		$primary      = $this->getPrimaryName();
		$phalconModel = $this->createTableModel($model);
		
		if ($transaction !== null) {
			$phalconModel->setTransaction($transaction);
		}
		
		// If the primary is unresolvable, let's phalcon try it
		if ($primary === null) {
			return $phalconModel->save();
		}

		// Insert or Update resolving
		$isInsert = $model->isInsertForced();

		if (is_array($primary)) {
			foreach ($primary as $part) {
				if (! isset($model->$part)) {
					$isInsert = false;
				}
			}
		} else if (is_string($primary) && ! isset($model->$primary)) {
			$isInsert = true;
		}

		// Do the insert
		if ($isInsert) {
			$result = $phalconModel->create();
			$model->unforceInsert();

			// Put the primary data into the model after inserting
			if (is_array($primary)) {
				foreach ($primary as $part) {
					if (isset($phalconModel->$part)) {
						$model->$part = $phalconModel->$part;
					}
				}
			} else if (isset($phalconModel->$primary)) {
				$model->$primary = $phalconModel->$primary;
			}

			return $result;
		}

		// Do the update
		return $phalconModel->update();
	}
718314
public function save(Model\EnvironmentInterface $environment, Model\EnvironmentInterface $cloneFrom = null)
    {
        $content = $this->getEnvironmentHydrator()->extract($environment);
        if ($cloneFrom != null) {
            $content['cloneFrom'] = strval($cloneFrom->getNormalizedName());
        }
        $this->pmProxyClient->put('/environments/' . $environment->getNormalizedName(), $content);
        if ($environment->hasChildren()) {
            foreach ($environment->getChildren() as $child) {
                /** @var Model\EnvironmentInterface $child */
                if ($cloneFrom) {
                    $this->save($child, $cloneFrom->getChildByName($child->getName()));
                } else {
                    $this->save($child);
                }
            }
        }
        return $this;
    }
711696
public function getPdf(PdfDocument $model, AbstractModel $parent = null)
    {
        return $this->request($this->buildUrl($model, $parent, null, 'pdf'), 'GET');
    }
198736
public function build(AbstractModel $model): void {
		$this->sort($model);

		$this->buildHeader($model);

		// signature
		$this->buildSignature($model);

		// body
		$this->writer->writeln(" {\n")->indent();
		$this->buildTraits($model);
		$this->buildConstants($model);
		$this->buildProperties($model);
		$this->buildMethods($model);
		$this->writer->outdent()->rtrim()->write('}');
	}
948933
public function contains(AbstractModel $model)
    {
        foreach ($this->storage as $key => $storedModel) {
            if ($model === $storedModel->getModel()) {
                return true;
            }
        }

        return false;
    }
1354454
protected function set($property, AbstractModel $model)
    {
        $key = $model->getCompositeKey();
        $this->{$property}[$key] = $model;

        if ('models' === $property) {
            $keys = array_flip($this->modelKeyMap);
            if (!isset($keys[$key])) {
                $this->modelKeyMap[] = $key;
                $this->totalCount++;
            }
        }
        return $this;
    }
194222
public function destroy($parent = null, $model = null)
    {
        if ($this->repository->delete($model)) {
            return back();
        }
    }
451913
public function save(Model $model)
    {
        $database = $model->getSourceDB();
        $pkey = $model->getID();

        if ($database === null || $database !== $this->db)
            $this->insert($model);
        else
            $this->update($model);

        return $this;
    }
1145355
public function persist(AbstractModel $model, $forceInsert = false)
    {
        $retval = false;
        try {
            list ($query, $param, $type) = $this->getPersistData($model, $forceInsert);
            $stmt = $this->prepare($query, $param);

            if ($stmt->execute()) {

                if ($type == MySQLQueryBuilder::INSERT_QUERY) {
                    $this->setModelPrimaryKey($this->db->getLastInsertId(), $model);
                }

                $retval = true;
            } else {
                $this->log(ILog::T_ERROR, print_r($stmt->errorInfo()), true);
                $retval = false;
            }
        } catch (\Exception $e) {
            $this->log(ILog::T_ERROR, $e->getMessage(), true);
            return false;
        }

        // add to the modelCache
        $this->modelCache->set($model);

        return $retval;
    }
288126
public static function saveOrder($tree = [], $parentId = 0)
    {
        if (empty(static::$branchOrder)) {
            static::setBranchOrder($tree);
        }

        foreach ($tree as $branch) {
            $node = static::find($branch['id']);

            $node->{$node->getParentColumn()} = $parentId;
            $node->{$node->getOrderColumn()} = static::$branchOrder[$branch['id']];
            $node->save();

            if (isset($branch['children'])) {
                static::saveOrder($branch['children'], $branch['id']);
            }
        }
    }
1046893
private function parentsOf($model, &$parents)
    {
        $environment    = $this->getEnvironment();
        $dataDefinition = $environment->getDataDefinition();
        $collector      = new ModelCollector($this->getEnvironment());
        $relationships  = new RelationshipManager(
            $dataDefinition->getModelRelationshipDefinition(),
            $dataDefinition->getBasicDefinition()->getMode()
        );

        if (!$relationships->isRoot($model)) {
            $parent = $collector->searchParentOf($model);
            if (!isset($parents[$model->getProviderName()][$parent->getId()])) {
                $this->parentsOf($parent, $parents);
            }
        }

        $parents[$model->getProviderName()][$model->getId()] = 1;
    }
614976
public function addChildObject($alias, $parent_id, $model, $foreignKey) {
        $query = array(
            'alias' => $alias,
            'parent_id' => $parent_id,
            'model' => $model,
            'foreign_key' => $foreignKey
        );

        $result = $this->find('first', array(
            'conditions' => $query
        ));

        if ($result) {
            return $result;
        }

        $this->create();

        if ($this->save($query)) {
            $this->deleteCache(array('RequestObject::hasAlias', $alias));

            return $this->getByAlias($alias);
        }

        return null;
    }
573178
private function saveTermsRelation(\Magento\Framework\Model\AbstractModel $object)
    {
        $termRelations = $object->getTermsRelations();
        $termRelations = array_filter($termRelations);

        if (is_array($termRelations) && (count($termRelations) > 0)) {
            $expansionTermLinks = [];
            $referenceTermLinks = [];

            $termId = 0;
            foreach ($termRelations as $termData) {
                $termId++;

                if ($object->getType() === ThesaurusInterface::TYPE_EXPANSION) {
                    $referenceTermLinks[] = [
                        'term_id'                        => $termId,
                        'term'                           => trim(strtolower($termData['reference_term'])),
                        ThesaurusInterface::THESAURUS_ID => (int) $object->getThesaurusId(),
                    ];
                }

                $termList = explode(",", $termData['values']);
                foreach ($termList as $term) {
                    $expansionTermLinks[] = [
                        'term_id'                        => $termId,
                        'term'                           => trim(strtolower($term)),
                        ThesaurusInterface::THESAURUS_ID => (int) $object->getThesaurusId(),
                    ];
                }
            }

            $this->deleteThesaurusRelations($object);

            // Saves expansion terms for a thesaurus. Expansion terms are used by expansion AND synonym thesauri.
            $this->getConnection()->insertOnDuplicate(
                $this->getTable(ThesaurusInterface::EXPANSION_TABLE_NAME),
                $expansionTermLinks,
                array_keys(current($expansionTermLinks))
            );

            $this->saveReferenceTerms($object, $referenceTermLinks);
        }
    }
846988
public function get(AbstractModel $model, $param = null)
    {
        if ($this->contains($model)) {
            return $this->storage[md5($this->generateHash($model) . json_encode($param))]->getModel();
        }

        return null;
    }