Closed bogdancochioras closed 5 years ago
@bogdancochioras You can try to to use @json field (https://github.com/Nozbe/WatermelonDB/blob/master/docs/Advanced/AdvancedFields.md#json) with its sanitizer function, but value will be always stored as a string (or null). You can also use another indirect field of model class, defined as getter/setter, to process value before get/set in @field.
I
@bogdancochioras You can try to to use @JSON field (https://github.com/Nozbe/WatermelonDB/blob/master/docs/Advanced/AdvancedFields.md#json) with its sanitizer function, but value will be always stored as a string (or null). You can also use another indirect field of model class, defined as getter/setter, to process value before get/set in @field.
I wanted to go with the second option you mentioned but thought there might be a more direct way to not change code implementation which already set data directly in the field
to not change code implementation which already set data directly in the field
You can simply change the name of your @field('x') x
to @field('x') _x
, and create indirect getter/setter called x
to process data before set it to '_x'. There is no other way to overwrite setter of @field.
@bogdancochioras Closing, assuming this is a solved issue
Hello, I have the following declaration for a field on a model:
@field('x') x;
Is it possible to override setter for this field on the model? How could I achieve that to not handle the value where I call the CRUD methods?