You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using global scopes to load some "virtual fields" to some models (something like this). But when these models are sent to the queue, they are serialized and then restored without the global scopes.
I found the PR that introduced this behavior here and the example used there is the soft-deleting scope. I do agree that if we queue a soft-deleted model, we probably don't want the job to "fail" (which would be the case if we had the soft-delete scope applied to model restoration), but I do think it makes sense to load some scopes globally (hence the name).
I ended up overriding my base model to restore models with global scopes, except the soft-deleting one. But I was curious if we shouldn't handle it in the FW itself. Feels like this scenario is more common these days (that's my impression).
A couple ways we could solve it:
Register all global scopes except for the soft deleting one;
Somehow allow defining in the global scope registration if the global scope should be used for restoration;
Or should I just not use global scopes for these "virtual fields"?
Thoughts?
PS.: I borrowed the term "virtual fields" from CakePHP, but it's just a way to describe the problem (see reference)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using global scopes to load some "virtual fields" to some models (something like this). But when these models are sent to the queue, they are serialized and then restored without the global scopes.
I found the PR that introduced this behavior here and the example used there is the soft-deleting scope. I do agree that if we queue a soft-deleted model, we probably don't want the job to "fail" (which would be the case if we had the soft-delete scope applied to model restoration), but I do think it makes sense to load some scopes globally (hence the name).
I ended up overriding my base model to restore models with global scopes, except the soft-deleting one. But I was curious if we shouldn't handle it in the FW itself. Feels like this scenario is more common these days (that's my impression).
A couple ways we could solve it:
Or should I just not use global scopes for these "virtual fields"?
Thoughts?
PS.: I borrowed the term "virtual fields" from CakePHP, but it's just a way to describe the problem (see reference)
Beta Was this translation helpful? Give feedback.
All reactions