Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragment serializer does not work if an array was changed #403

Open
josegetout opened this issue Jul 15, 2021 · 1 comment
Open

Fragment serializer does not work if an array was changed #403

josegetout opened this issue Jul 15, 2021 · 1 comment

Comments

@josegetout
Copy link

josegetout commented Jul 15, 2021

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

@knownasilya
Copy link
Collaborator

Can you share the code where you change the values and serialize?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants