Esempio n. 1
0
 /**
  * Insert an entity's DB row using the given values.
  * Set the ID on the entity from the query result.
  *
  * @param  AbstractEntity $entity
  */
 protected function insertRow(AbstractEntity $entity)
 {
     $values = $entity->getDbValues();
     $columns = array_keys($values);
     if ($this->autoIncrementColumn && !array_key_exists($this->autoIncrementColumn, $values)) {
         throw new LogicException('auto_increment column ' . $this->autoIncrementColumn . ' not found');
     }
     $query = $this->getSqlObject()->insert()->columns($columns)->values($values);
     $statement = $this->getSqlObject()->prepareStatementForSqlObject($query);
     $result = $statement->execute();
     if ($this->autoIncrementColumn && !$values[$this->autoIncrementColumn]) {
         $entity->exchangeArray([$this->autoIncrementColumn => $result->getGeneratedValue()]);
     }
 }
Esempio n. 2
0
 /**
  * Update an entity's DB row by its ID.
  * Set the updated timestamp column if it exists.
  *
  * @param  AbstractEntity $entity
  * @param  array          $values Values to set on the entity
  */
 protected function updateRow(AbstractEntity $entity)
 {
     $values = $entity->getDbValues();
     $query = $this->getSqlObject()->update()->set($values)->where($this->getPrimaryKeyWheres($entity));
     $this->execute($query);
 }