-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Description
- Laravel Version: 5.3.x
- PHP Version: 7.1
- Database Driver & Version: MySql
Description:
'Touches' updates touched models updated_at timestamp when child model performs an update with no dirty data (thus no updated_at change on child model).
Steps To Reproduce:
Using the example from the docs:
https://laravel.com/docs/5.4/eloquent-relationships#touching-parent-timestamps
Performing an update with no dirty data on the 'comment' model would result in the 'post' model's updated_at timestamp being updated, while the 'comment' model does not (due to it not being dirty).
Is this expected behaviour or a bug? Happy to put in a PR to fix, it's in the snippet below where the $saved = isDirty... ternary sets $saved to true when the data on the model isn't dirty... and thus finishSave() gets called which updates parent timestamps.
// If the model already exists in the database we can just update our record
// 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->isDirty() ?
$this->performUpdate($query) : true;
}
// If the model is brand new, we'll insert it into our database and set the
// ID attribute on the model to the value of the newly inserted row's ID
// which is typically an auto-increment value managed by the database.
else {
$saved = $this->performInsert($query);
}
if ($saved) {
$this->finishSave($options);
}
JasonMortonNZ, adiachenko and baceto90
Metadata
Metadata
Assignees
Labels
No labels