/** * @return bool|int */ public function save() { if (!$this->dirty) { return false; } if (!is_null($this->id)) { // update self::$sqlBuilder->where(static::primaryKey(), '=', $this->id); $sql = self::$sqlBuilder->update(static::tableName(), $this->fields); } else { // insert $sql = self::$sqlBuilder->insert(static::tableName(), $this->fields); } $this->dirty = false; if ($result = static::$db->run($sql)) { $this->id = static::$db->lastInsertId(); return true; } return false; }