adopted-ember-addons / ember-data-model-fragments

Ember Data addon to support nested JSON documents
MIT License
370 stars 114 forks source link

updating a fragment's attribute in a form doesn't set the fragment as dirty #340

Open Leooo opened 5 years ago

Leooo commented 5 years ago

Ember | 3.4.8 Ember Data | 3.5.2 jQuery | 2.1.4 Model Fragments | 4.0.0

//models/appointment.js
export default Model.extend({
  telephoneNumber: MF.fragment('phone-type')
});
//models/phone-type.js
export default MF.Fragment.extend({
  type: DS.attr('string'),
  number: DS.attr('string')
});

(existing appointment)

appointment.changedAttributes(); // {}
appointment.set('telephoneNumber.number', '07777777777');
appointment.changedAttributes(); // {}
appointment.telephoneNumber.changedAttributes(); // {number: Array(2)}

So appointment.changedAttributes() is not updated, which prevents the telephoneNumber to be serialized (at least when using ember-data-change-tracker, but I think it's an ember-data-model-fragments problem).

Anyone else seeing this? Can try to create a jsfiddle or test if needed.

Leooo commented 5 years ago

someone needs to add https://ember-twiddle.com/ on top of SEO for "Ember jsfiddle"

Leooo commented 5 years ago

so on https://ember-twiddle.com/499e21ed033ff8270dcd966904b02c4c?openFiles=routes.application.js%2C, things work.. Can't reproduce on ember-twiddle then :(

hew commented 1 year ago

Not ideal, but you can manually set it dirty:

send('becomeDirty');