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

[QUESTION] [3.0.0-beta.1] Is the fragmentArray ordering important when saving and updating?

Open
#359 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
367
Forks
108
PR merge metrics
No merged PRs in 30d

Description

Hi,

## Context

I don't have much experience using fragments.

* I have a `fragmentArray` and I am manipulating the objects, adding and removing them.
* These are the version of the related addons:

```json
"ember-data": "3.1.2",
"ember-data-model-fragments": "3.0.0-beta.1",
```

**Note:** As always, willing to upgrade

* The array is created in the `normalizeResponse` serializer of the owner.

## Problem

In a template I iterate the objects of the fragment, I manipulate the fragments using: `removeFragment` and `addFragment` to add and remove (which seems to be simple wrappers for `addObjects` and `removeObjects`).

I am even calling destroy in the removed objects using `.destroy()` after removing it from the fragment. But, even when doing that, the fragment array gets mess up after saving the parent model, even though the response is correct when it gets to the parent serializer and seems to be correct until the point when Ember data push it into the store.

## Work around that seems to work

If I sort the array by a unique object key when adding new objects and when I get it them serializer, everything seems to work ok. It seems like somehow, the array ordering is important to keep consistency when manipulated fragments inside the fragment array.

## Questions

* Is the ordering of a `fragmentArray` ordering to keep consistency?
* How do I remove fragments completely from the store?

Best regards,
Daniel.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.