Example #1
0
 private function create(Model $model)
 {
     $idProperty = $model->GetIDProperty();
     // merged array containing original plus modified properties
     $merged = array_replace_recursive($model->GetProperties(), $model->GetModifiedProperties());
     $cols = [];
     $types = [];
     $values = [];
     foreach ($merged as $property => $dbMap) {
         if ($property !== $idProperty) {
             $cols[] = $dbMap['col'];
             $types[] = $dbMap['type'];
             $values[$dbMap['col']] = $dbMap['value'];
         }
     }
     $sql = "INSERT INTO {$model->GetDbTable()} (" . implode(',', $cols) . ") VALUES (:" . implode(',:', $cols) . ")";
     $this->writer->executeQuery($sql, $values, $types);
     $insertId = $this->writer->lastInsertId();
     $model->SetID($insertId);
 }