Last active
May 23, 2017 04:36
-
-
Save runspired/734a5637cadae3bd9e2f6fabd9b9421b to your computer and use it in GitHub Desktop.
ED Relationship Bug #4991
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
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(); | |
} | |
} |
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: 'REPL #4991', | |
init() { | |
this._super(); | |
this.record = this.get('store').findRecord('role', 1); | |
} | |
}); |
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({ | |
name: attr(), | |
manager: belongsTo('role', { inverse: 'subordinants', async: true }), | |
subordinants: hasMany('role', { inverse: 'manager', async: true }) | |
}); |
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
export default class Serializer { | |
normalizeResponse(_, __, data) { | |
return data; | |
} | |
static create() { | |
return new Serializer(); | |
} | |
} |
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.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