Beispiel #1
0
 /**
  * Inserts a new record into the database.
  *
  * @access  protected
  * @param   \mako\database\midgard\Query  $query  Query builder
  */
 protected function insertRecord($query)
 {
     if ($this->primaryKeyType === static::PRIMARY_KEY_TYPE_INCREMENTING) {
         $this->columns[$this->primaryKey] = $query->insertAndGetId($this->columns, $this->primaryKey);
     } else {
         switch ($this->primaryKeyType) {
             case static::PRIMARY_KEY_TYPE_UUID:
                 $this->columns[$this->primaryKey] = UUID::v4();
                 break;
             case static::PRIMARY_KEY_TYPE_CUSTOM:
                 $this->columns[$this->primaryKey] = $this->generatePrimaryKey();
                 break;
         }
         $query->insert($this->columns);
     }
 }
Beispiel #2
0
 /**
  * @expectedException \mako\database\midgard\ReadOnlyRecordException
  */
 public function testInsertWithException()
 {
     $model = $this->getModel();
     $model->shouldReceive('isReadOnly')->twice()->andReturn(true);
     $model->shouldReceive('getTable')->once()->andReturn('tests');
     $query = new Query($this->getConnecion(), $model);
     $query->insert(['foo' => 'bar']);
 }