Last active
December 10, 2018 21:13
-
-
Save danielspaniel/983bf2f8ac50eaf7c5f1ffd3bdc6839b to your computer and use it in GitHub Desktop.
hasMany can update if you push values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.JSONAPIAdapter.extend({ | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ | |
name: attr('string'), | |
things: hasMany('thing') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
beforeModel() { | |
let data = { | |
data: { | |
id: 1, | |
type: 'person', | |
relationships: { | |
things: { | |
data: [ | |
] | |
} | |
} | |
}, | |
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 to put | |
person.set('things', things); | |
// or this also shows same behaviour | |
// person.get('things').pushObject(thing); | |
let data = { | |
id: 1, | |
type: 'person', | |
relationships: { | |
things: { | |
data: [ | |
{id: 2, type: "thing"} | |
] | |
} | |
} | |
}; | |
// this will add one thing to the things a person has | |
this.store.pushPayload({data}); | |
return person; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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