*/
public function update(BaseModel $model)
{
- return $this->dba->update(static::$table_name, $model->toArray(), ['id' => $model->id], true);
+ if ($this->dba->update(static::$table_name, $model->toArray(true), ['id' => $model->id], $model->getOriginalData())) {
+ $model->resetOriginalData();
+ return true;
+ }
+
+ return false;
}
/**
{
$return = $this->dba->insert(static::$table_name, $fields);
- if ($return) {
- $fields['id'] = $this->dba->lastInsertId();
- $return = $this->create($fields);
+ if (!$return) {
+ throw new HTTPException\InternalServerErrorException('Unable to insert new row in table "' . static::$table_name . '"');
}
+ $fields['id'] = $this->dba->lastInsertId();
+ $return = $this->create($fields);
+
return $return;
}
return $models;
}
+
+ /**
+ * @param BaseCollection $collection
+ */
+ public function saveCollection(BaseCollection $collection)
+ {
+ $collection->map([$this, 'update']);
+ }
}