-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.1] Fix timestamps on update #12403
Conversation
Since we're not updating timestamps if |
To me it feels really, really silly to have this new property that we are setting to true / false at random times. I don't know, something about this all feels really hacky. |
Yeah it is a bit hacky but I don't have any other idea right now on how to fix it without breaking BC. Let me look at this a bit more tomorrow. Maybe I can find some better alternative. |
I mean just off the top of my head. What if something in a model updated event updates a different field on the model and does want the timestamps updated? |
As a reminder, That's a good example of what could happen when a test has to hook mocks into the implementation of what is being tested. |
@taylorotwell I found a better solution. I added a method User::withoutTimestamps()->update(['active' => 1]); @vlakoff Yeah mocking Eloquent is never a good idea. That's why I added a proper integration test for this issue. |
I don't even really want to support this at all. If you want to update a DB record without updating the timestamps use the query builder. This will lead to all kinds of more code to support weird edge cases where I want to not update the timestamps on the main model but I want to touch or not touch the parent models, etc. I don't even want to go down this rabbit hole. |
This fixes #10028 where timestamps are updated even if
['timestamps' => false]
is passed to thesave()
method.The easiest solution would be to simply pass the
$options
array to the update method on theBuilder
but since that would be a breaking change (someone may be extending the Builder) I added a new flag$shouldUpdateTimestamps
that is set tofalse
if timestamps were disabled.