Skip to content

Commit

Permalink
Touch owners on save only if model is dirty (#14214)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-har authored and taylorotwell committed Jul 12, 2016
1 parent af0a287 commit 7af9cd1
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ public function save(array $options = [])
// that is already in this database using the current IDs in this "where"
// clause to only update this model. Otherwise, we'll just insert them.
if ($this->exists) {
$saved = $this->performUpdate($query);
$saved = $this->isDirty() ? $this->performUpdate($query) : false;
}

// If the model is brand new, we'll insert it into our database and set the
Expand Down Expand Up @@ -1525,33 +1525,29 @@ protected function finishSave(array $options)
*/
protected function performUpdate(Builder $query)
{
$dirty = $this->getDirty();

if (count($dirty) > 0) {
// If the updating event returns false, we will cancel the update operation so
// developers can hook Validation systems into their models and cancel this
// operation if the model does not pass validation. Otherwise, we update.
if ($this->fireModelEvent('updating') === false) {
return false;
}
// If the updating event returns false, we will cancel the update operation so
// developers can hook Validation systems into their models and cancel this
// operation if the model does not pass validation. Otherwise, we update.
if ($this->fireModelEvent('updating') === false) {
return false;
}

// First we need to create a fresh query instance and touch the creation and
// update timestamp on the model which are maintained by us for developer
// convenience. Then we will just continue saving the model instances.
if ($this->timestamps) {
$this->updateTimestamps();
}
// First we need to create a fresh query instance and touch the creation and
// update timestamp on the model which are maintained by us for developer
// convenience. Then we will just continue saving the model instances.
if ($this->timestamps) {
$this->updateTimestamps();
}

// Once we have run the update operation, we will fire the "updated" event for
// this model instance. This will allow developers to hook into these after
// models are updated, giving them a chance to do any special processing.
$dirty = $this->getDirty();
// Once we have run the update operation, we will fire the "updated" event for
// this model instance. This will allow developers to hook into these after
// models are updated, giving them a chance to do any special processing.
$dirty = $this->getDirty();

if (count($dirty) > 0) {
$numRows = $this->setKeysForSaveQuery($query)->update($dirty);
if (count($dirty) > 0) {
$numRows = $this->setKeysForSaveQuery($query)->update($dirty);

$this->fireModelEvent('updated', false);
}
$this->fireModelEvent('updated', false);
}

return true;
Expand Down

0 comments on commit 7af9cd1

Please sign in to comment.