atk4\data\Model::import PHP Method

import() public method

Will be further optimized in the future.
public import ( $rows )
    public function import($rows)
    {
        $m = clone $this;
        foreach ($rows as $row) {
            $this->_rawInsert($m, $row);
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testModelInsertRows()
 {
     $a = ['user' => [1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones']]];
     $p = new Persistence_SQL('sqlite::memory:');
     $p->connection->expr('drop table if exists user')->execute();
     $p->connection->expr('create table user(id integer primary key autoincrement, name varchar(255), surname varchar(255))')->execute();
     $m = new Model($p, 'user');
     $m->addField('name');
     $m->addField('surname');
     $m->import($a['user']);
     $this->assertEquals(2, $m->action('count')->getOne());
 }