Example #1
0
 /**
  * Save this row, inserting if it is a new row and updating otherwise.
  *
  * @return $this
  */
 public function save()
 {
     if (!$this->isNew()) {
         $updateData = $this->data;
         $this->table->update($updateData, $this->assembleUpdateWhereClause());
         $this->getTable()->getActivityLogHandler()->triggerFieldChangeEvents($this);
     } else {
         $id = $this->table->insert($this->data);
         // Set value of auto-incrementing primary key, if available
         if ($id) {
             $this->set(current($this->table->getPrimaryKey()), $id);
         }
     }
     $this->refresh();
     return $this;
 }
Example #2
0
 /**
  * Save this row, inserting if it is a new row and updating otherwise.
  *
  * @return \Dewdrop\Db\Row
  */
 public function save()
 {
     if (!$this->isNew()) {
         $updateData = $this->getUpdatedData();
         if (!empty($updateData)) {
             $this->table->update($updateData, $this->assembleUpdateWhereClause());
         }
     } else {
         $id = $this->table->insert($this->data);
         // Set value of auto-incrementing primary key, if available
         if ($id) {
             $this->set(current($this->table->getPrimaryKey()), $id);
         }
     }
     $this->refresh();
     return $this;
 }