atk4\data\Model::insert PHP Method

insert() public method

Will be further optimized in the future.
public insert ( array $row ) : mixed
$row array
return mixed
    public function insert($row)
    {
        $m = clone $this;
        $this->_rawInsert($m, $row);
        return $m->id;
    }

Usage Example

Example #1
0
 public function testInsert()
 {
     $a = ['user' => [1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones']]];
     $p = new Persistence_Array($a);
     $m = new Model($p, 'user');
     $m->addField('name');
     $m->addField('surname');
     $m->insert(['name' => 'Foo', 'surname' => 'Bar']);
     $this->assertEquals(['user' => [1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones'], 3 => ['name' => 'Foo', 'surname' => 'Bar', 'id' => 3]]], $a);
 }
All Usage Examples Of atk4\data\Model::insert