Skip to content

Instantly share code, notes, and snippets.

@shidel-dev
Last active January 10, 2019 20:38
Show Gist options
  • Save shidel-dev/0c2b479da0ccc3c2acaf5b3513da180b to your computer and use it in GitHub Desktop.
Save shidel-dev/0c2b479da0ccc3c2acaf5b3513da180b to your computer and use it in GitHub Desktop.
ember data included issue
import Adapter from "ember-data/adapters/json-api";
export default Adapter.extend();
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
loadData: function() {
let store = this.get("store");
let json = {
data: {
id: "1",
type: "child",
attributes: {
id: "1",
name: "child1"
},
relationhips: {
parent: {
type: "adult",
id: "2"
}
},
},
included: [
{
id: "2",
type: "adult",
attributes: {
id: "2",
name: "parent"
},
relationships: {
type: "children",
children: [{id: "1", type: "child"}]
}
},
{
id: "1",
type: "child",
attributes: {
id: "1",
name: "child1"
},
relationships: {
parent: {
id: "2",
type: "parent"
}
}
}
]
}
store.push(json)
console.log(store.peekAll("child").toArray())
console.log(store.peekAll("adult").toArray()[0].get("children").toArray())
}
}
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
children: hasMany("children"),
name: attr("string")
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
parent: belongsTo("adult"),
name: attr("string")
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<button {{action "loadData"}}>
Press this
</button>
{{outlet}}
<br>
<br>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "2.13.0",
"ember-template-compiler": "2.13.0",
"ember-testing": "2.13.0"
},
"addons": {
"ember-data": "2.13.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment