ember-data-model-fragments
ember-data-model-fragments copied to clipboard
Fragment serializer does not work if an array was changed
Hi! I'm struggling serializing my fragment model. I've found out that it never serializes the model if I add/removes elements in an array and it only does it if I change any other attribute.
This is my model:
import { attr } from '@ember-data/model';
import MF from 'ember-data-model-fragments';
export default class extends MF.Fragment {
@attr('string') name
@attr('string') parametrizedUrl
@attr('string') url
@attr('array', { defaultValue() { return []; } }) urlParameters
}
This is the serializer:
import JSONSerializer from 'ember-data/serializers/json';
export default class extends JSONSerializer {
serialize(snapshot, options) {
const json = super.serialize(snapshot, options);
if (json.url_parameters.length) {
json.parametrized_url = this.createParametrizedURL(json.url, json.url_parameters);
}
return json;
}
}
The thing is that I want to generate a parametrized URL with the elements inside the array but it never execute the seralize method if I change only the elements of the array because it does not recognize that any change has been made. For example, if I change the name and the array then it serialize my model. Can anyone help me? I'm kinda lost with fragments
Can you share the code where you change the values and serialize?