I have a model:
export default Model.extend({
title: attr('string'),
attributes: attr('jsonb')
});
Where attributes
is a custom json
filed stored as jsonb
in Postgres.
let say:
{
"name":"Bob",
"city":""
}
So I can easily manipulate attributes
using template
<form.element .. @property="attributes.city"/>
or model.set('attributes.city','city name')
Problem: hasDirtyAttributes
do not changing because technically we have old object. But when I try to copy object let say JSON.parse(JSON.stringify(this.get('attributes'))
hasDirtyAttributes
works as expected
So how to write some Mixin
for a Model
or other workaround which on the change of any attribute
property will mark hasDirtyAttributes
as true
. I will update whole object so doesn't matter which property actually was changed.
Same problem: https://discuss.emberjs.com/t/hasdirtyattributes-do-not-work-with-nested-attributes-json-api/15592
existing solution doesn't work for me at all:
- ember-dirtier
- ember-data-relationship-tracker
- ember-data-model-fragments (a lot of changes under the hood and broke my app)
Aucun commentaire:
Enregistrer un commentaire