/** * insertOne * * Insert a new entity in the database. The entity is passed by reference. * It is updated with values returned by the database (ie, default values). * * @access public * @param FlexibleEntityInterface $entity * @return Model $this */ public function insertOne(FlexibleEntityInterface &$entity) { $values = $entity->fields(array_intersect(array_keys($this->getStructure()->getDefinition()), array_keys($entity->extract()))); $sql = strtr("insert into :relation (:fields) values (:values) returning :projection", [':relation' => $this->getStructure()->getRelation(), ':fields' => $this->getEscapedFieldList(array_keys($values)), ':projection' => $this->createProjection()->formatFieldsWithFieldAlias(), ':values' => join(',', $this->getParametersList($values))]); $entity = $this->query($sql, array_values($values))->current()->status(FlexibleEntityInterface::STATUS_EXIST); return $this; }