/**
  * @param AbstractModel $object
  */
 public function save(AbstractModel $object)
 {
     $record = $this->entityMapper->objectToRecord($object);
     if ($record['id']) {
         $where = ['id' => (int) $record['id']];
         $this->db->update($this->tablename, $record, $where);
     } else {
         $insertId = $this->db->insert($this->tablename, $record);
         $object->setId($insertId);
     }
 }
 /**
  * @test
  */
 public function insertAndUpdate()
 {
     $row = ['title' => 'insert_and_update_test'];
     $row['id'] = $this->fixture->insert('item', $row);
     $row['title'] = 'changed title';
     $this->fixture->update('item', $row, ['id' => $row['id']]);
     $queried_row = $this->fixture->row('item', '*', ['id' => $row['id']]);
     $this->assertSame($row['title'], $queried_row['title']);
 }
Esempio n. 3
0
 /**
  * @param int $version
  */
 protected function setCurrentMigrationVersion($version)
 {
     if (count($this->db->query("SHOW TABLES LIKE 'migration_ver'")) < 1) {
         $sql = "CREATE TABLE IF NOT EXISTS `migration_ver` (`version` int(11) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;";
         $this->db->execute($sql);
     }
     $data = ['version' => $version];
     if ($this->db->count('migration_ver') < 1) {
         $this->db->insert('migration_ver', $data);
     } else {
         $this->db->update('migration_ver', $data, ['version!' => '0']);
     }
 }