Esempio n. 1
0
 /**
  * Do create action.
  *
  * @param mixed $dataset The data set contains data we want to store.
  *
  * @throws \Exception
  * @return  mixed  Data set data with inserted id.
  */
 protected function doCreate($dataset)
 {
     !$this->useTransaction ?: $this->db->transactionStart(true);
     try {
         foreach ($dataset as $k => $data) {
             if (!$data instanceof $this->dataClass) {
                 $data = $this->bindData($data);
             }
             $entity = new Entity($this->getFields($this->table), $data);
             $pk = $this->getPrimaryKey();
             $this->db->create($this->table, $entity, $pk);
             $data->{$pk} = $entity->{$pk};
             $dataset[$k] = $data;
         }
     } catch (\Exception $e) {
         !$this->useTransaction ?: $this->db->transactionRollback(true);
         throw $e;
     }
     !$this->useTransaction ?: $this->db->transactionCommit(true);
     return $dataset;
 }