Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kumkanillam/3329fad2df4d3cb0de3f3a98098cb419 to your computer and use it in GitHub Desktop.
Save kumkanillam/3329fad2df4d3cb0de3f3a98098cb419 to your computer and use it in GitHub Desktop.
ED Relationship Bug #4991
const PAYLOADS = {
'1': {
data: {
type: 'role',
id: '1',
attributes: {
name: 'CEO'
},
relationships: {
subordinants: {
links: {
related: './<fake>/api/roles/1'
}
}
}
}
},
'./<fake>/api/roles/1': {
data: [
{
type: 'role',
id: '2',
attributes: {
name: 'CTO'
},
relationships: {
subordinants: {
links: {
related: './<fake>/api/roles/2'
}
}
}
},
{
type: 'role',
id: '3',
attributes: {
name: 'CFO'
},
relationships: {
subordinants: {
links: {
related: './<fake>/api/roles/3'
}
}
}
}
]
},
'./<fake>/api/roles/2': {
data: [
{
type: 'role',
id: '4',
attributes: {
name: 'Tech VP 1'
},
},
{
type: 'role',
id: '5',
attributes: {
name: 'Tech VP 2'
},
}
]
},
'./<fake>/api/roles/3': {
data: [
{
type: 'role',
id: '6',
attributes: {
name: 'Finance VP 1'
},
},
{
type: 'role',
id: '7',
attributes: {
name: 'Finance VP 2'
},
}
]
},
};
export default class Adapter {
findRecord() {
return Promise.resolve(PAYLOADS['1']);
}
findHasMany(_, __, relatedLink) {
return Promise.resolve(PAYLOADS[relatedLink]);
}
get() {
return null;
}
static create() {
return new Adapter();
}
}
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'REPL #4991',
init() {
this._super();
this.record = this.get('store').findRecord('role', 1);
}
});
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(),
manager: belongsTo('role', { inverse: 'subordinants', async: true }),
subordinants: hasMany('role', { inverse: 'manager', async: true })
});
export default class Serializer {
normalizeResponse(_, __, data) {
return data;
}
static create() {
return new Serializer();
}
}
<h1>Welcome to {{appName}}</h1>
<br>
<h1>Role: {{record.name}}</h1>
<ol>
{{#each record.subordinants as |role|}}
<li>
<h2>{{role.name}}</h2>
<ol>
{{#each role.subordinants as |subrole|}}
<li><h3>{{subrole.name}}</h3></li>
{{/each}}
</ol>
</li>
{{/each}}
</ol>
{{outlet}}
<br>
<br>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "~2.13.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment