/** * Saves the item back to the database. If item is loaded() it will result * in an update, otherwise a new row will be inserted * * @return \PHPixie\ORM\Model Returns self */ public function save() { if ($this->loaded()) { $query = $this->conn->query('update')->table($this->table)->where($this->id_field, $this->_row[$this->id_field]); } else { $query = $this->conn->query('insert')->table($this->table); } $query->data($this->_row); $query->execute(); if ($this->loaded()) { $id = $this->_row[$this->id_field]; } else { $id = $this->conn->insert_id(); } $row = (array) $this->conn->query('select')->table($this->table)->where($this->id_field, $id)->execute()->current(); $this->values($row, true); return $this; }