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

Removing Fragment from fragmentArray fails on PUT request #341

Open
prabakaranfresh opened this issue Oct 30, 2019 · 4 comments
Open

Removing Fragment from fragmentArray fails on PUT request #341

prabakaranfresh opened this issue Oct 30, 2019 · 4 comments

Comments

@prabakaranfresh
Copy link

Creating, Updating and Deleting fragments in Fragment Array works fine for a new model (isNew: true)

On an existing model from server, deleting a fragment inside fragmentArray removes it from the model and setting hasDirtyAttributes to true. But while saving the model using model.save empty object is sent to server (Only on PUT Request)

// app/models/person.js
import DS from 'ember-data';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
const { Model, attr } = DS;

export default Model.extend({
  name      : attr('string'),
  addresses : fragmentArray('address'),
  titles    : array()
});
// app/models/address.js
import attr from 'ember-data/attr';
import Fragment from 'ember-data-model-fragments/fragment';

export default Fragment.extend({
  street  : attr('string'),
  city    : attr('string'),
  region  : attr('string'),
  country : attr('string')
});
// Data from server
{
  "person"  : {
    "name"  : "Benedict Cumberbatch",
    "address" : [{
      "street"  : "77A Bleecker Street",
      "city"    : "New York City",
      "region"  : "New York",
      "country" : "US"
    }, {
      "street"  : "221B Baker Street",
      "city"    : "London",
      "region"  : "England",
      "country" : "UK"
    }],
    "titles" : ["Doctor Strange", "Sherlock Holmes"]
  }
}

I am removing one of the addresses from the fragmentArray

let addresses = this.model.get('addresses');
addresses.objectAt(0).removeFragment();
// Also Tried this =>
// addresses.objectAt(0).removeObject();
this.model.save();

After this the data sent to the server is an empty object

// Data to server
{}

When I remove any fragment from the fragmentArray, hasDirtyAttributes is set as true for the model and the fragmentArray. But no data was sent to server on PUT request using model.save()

Referred this Issue: Remove fragment from fragment array? But mine happens only on model.save()

@joshuamanns
Copy link

I just want to bump this issue as I'm having a very similar problem. Is this related to the open PR referenced here? #338

@prabakaranfresh
Copy link
Author

@joshuamanns My ember-data version is 3.10.0. Isn't the PR #338 is related to ember-data 3.13.0?

@joshuamanns
Copy link

@prabakaranfresh Were you ever able to resolve this? It's still a blocking issue for me and I'm debating if I should create an entire workaround instead of using fragments.

@prabakaranfresh
Copy link
Author

@joshuamanns I am having a workaround. I am forcing dirtyAttributes on removing fragments from fragments array.

addresses.map(address => address.send('becomeDirty'));

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