Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.22k stars 153 forks source link

Can't save base model changes with guarded attributes after getting translations #334

Closed slowcheetah closed 1 year ago

slowcheetah commented 1 year ago

Describe the bug If I use a model with guarded attributes instead of fillable, then I get an error when trying to save changed attributes of the base model. This behavior occurs only after accessing the translation field through a mutator. When accessed through a mutator, the translation attribute is stored in the model attributes and when getDirty is called, it starts to return.

To Reproduce

  1. Create model with guarded attributes and mutator for translation field.
  2. Get translation field via mutator
  3. Try to change some field of model and save

Expected behavior Save changes of base model instead exception

Versions (please complete the following information)

Exception General error: 1 no such column: name (Connection: testing, SQL: update "cities" set "category" = some_category, "name" = Oslo, "locale" = En, "updated_at" = 2023-02-24 10:06:00 where "id" = 1) name is translation field.

Gummibeer commented 1 year ago

Like written in #335 - that's simply wrong usage, so not a bug and also not expected to be fixed.