-
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.3] Allow SerializesModels
to optionally restore models excluded by global scope (SoftDeletes
, for example)
#16301
[5.3] Allow SerializesModels
to optionally restore models excluded by global scope (SoftDeletes
, for example)
#16301
Conversation
Personally it seems like it should always be without scopes and not even be configurable. If you queued the model instance surely that means you want it to be available. |
That's what I thought at first, but I can think of some cases where that's not true. For example, say you queued an email to a user to be delivered in 3 hours and then deleted the user for some reason 2 hours later—in that case you probably wouldn't want the job to run. I could see a strong argument for defaulting |
Yeah, I can't decide there. I mean that sounds fairly edge case and could be mitigated by checking if the user has been deleted or not before sending the email. I'm still of the opinion it should be without scopes by default. |
I'll update tonight making no scopes the default. I don't think it hurts much to make it configurable, especially because it's a pretty big pain to modify this particular behavior via inheritance/composition. |
SerializesModels
to optionally restore models excluded by global scope (SoftDeletes
, for example)SerializesModels
to optionally restore models excluded by global scope (SoftDeletes
, for example)
Looks like a nice idea. 👍 |
Done. |
I tweaked this a bit. If you want scopes you can just override the |
Oh, good call. That's certainly simpler is we assume that most people won't want to change this. |
Currently, if you want to queue jobs with deleted models (or anything else restricted by default via a global scope), you cannot use
SerializesModels
. This change adds a method toIlluminate/Queue/SerializesAndRestoresModelIdentifiers
calledrestoresModelsWithoutScopes()
, which returnsfalse
by default, but can be overridden by classes that use it to change this behavior.Now you can do:
By having
restoresModelsWithoutScopes()
returntrue
, thegetRestoredPropertyValue()
method will callnewQueryWithoutScopes()
instead ofnewQuery()
.