-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Massively update doesnt update default locale when model has early load relation 'translation' #215
Comments
Hey, I will keep this issue open and add proper labels so the community or you can possibly fix it. I will also merge it in v11 - as long as it's not a massive or too complicated change - I have some ideas that could solve and are relatively simple but no time to check. One is to check if the Keep in mind that this effort could be removed in the next major version. I will also stand my ground in the rating of this issue as "not a bug". |
I think adding a I've always used $wit = ['translations']; but in most requests (when users visit the site) all translations are loaded and more memory is consumed (not good). The option using scope I see 2 options for solving the problem:
|
Both scenarios will keep the problem that both relations are out of sync. So I would prefer a solution that at least unsets the singular relation after saving so that all relations/models have the same data. $post->translation; // en
$post->update(['en' => ..., 'de' => ..., 'fr' => ...]); // runs update only on ->translations
$post->translation != $post->translations['en']; This is only pseudo-code but should showcase the problem I mean. 😉 |
I agree. Maybe then just destroy the translation relation before filling the model? public function fill(array $attributes)
{
if ($this->relationLoaded('translation')) {
$this->unsetRelation('translation');
}
// ...
} |
I would do it post save - to prevent unsetting it if the save fails. But in general: yes. |
@Gummibeer If I understand you correctly, then here is the solution: |
Describe the bug
If you specify in the model
$with = ['translation']
(not 'translations'!) and massively update the model with translations (using update method), then the fields with the default locale are not updated.If you prescribe
$with = ['translations']
everything works correctly.To Reproduce
Add to Country model (in tests directory)
Then create test
The Test was failed with result:
Expected behavior
In spite of the fact that early loading is specified in the model
$with = ['translation']
- the bulk update must take place completely (for all languages).Versions (please complete the following information)
The text was updated successfully, but these errors were encountered: