Example #1
0
 /**
  * @return bool|mixed
  * @throws \Exception
  */
 public function save()
 {
     static::$db->setModel(get_class(new static()), static::$table);
     if ($this->isNewRow) {
         if (static::$db->insert($this->data, true)) {
             $this->isNewRow = false;
             if ($lastInsertID = static::$db->lastInsertId()) {
                 $newData = static::$db->table(static::$table)->select()->where($this->primaryKey, $lastInsertID)->first();
                 $this->data = is_array($newData) ? $newData : $this->data;
             }
             return true;
         }
         return false;
     } else {
         return static::$db->update($this->data, $this->primaryKey);
     }
 }