Skip to content

Instantly share code, notes, and snippets.

@hjdivad
Forked from danielspaniel/adapters.application.js
Created February 16, 2017 03:19
Show Gist options
  • Save hjdivad/d0c484a56032cd6f511f2b31eabdeb40 to your computer and use it in GitHub Desktop.
Save hjdivad/d0c484a56032cd6f511f2b31eabdeb40 to your computer and use it in GitHub Desktop.
hasMany not cleared by pushPayload
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddles',
thingIds: Ember.computed.mapBy('model.things', 'id'),
thingState: Ember.computed.mapBy('model.things', 'isDeleted')
});
import Ember from 'ember';
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
things: hasMany('thing')
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
person: belongsTo('person')
});
import Ember from 'ember';
export default Ember.Route.extend({
beforeModel() {
let data = {
data: {
id: 1,
type: 'person',
relationships: {
things: {
data: [
{id: 1, type: 'thing'},
{id: 2, type: 'thing'},
]
}
}
},
included: [
{id: 1, type: "thing"},
{id: 2, type: "thing"}
]
};
this.store.pushPayload(data);
},
model() {
let person = this.store.peekRecord('person', 1);
let things = this.store.peekAll('thing');
let [thing] = things.toArray();
// set 2 thing on the person
//person.set('things', things);
// or this also shows same behaviour
// person.get('things').pushObject(thing);
let data = {
id: 1,
type: 'person',
relationships: {
things: {
data: []
}
}
};
// this should clear the things from the person
this.store.pushPayload({data});
return person;
}
});
<h3>Welcome to Bug where pushPaylod does not clear hasMany relationship</h3>
<br>
My things ids:{{thingIds}}
<br>
I should have 0 things but I have:{{model.things.length}}
{{outlet}}
<br>
<br>
{
"version": "0.11.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js",
"ember": "2.10.2",
"ember-data": "release",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment