Last active
March 20, 2019 22:41
-
-
Save runspired/fb1cd61a85d6b206d4d688c6733f400e to your computer and use it in GitHub Desktop.
Relationship Reload Issue
This file contains 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 { Promise } from 'rsvp'; | |
export default class AppAdapter { | |
constructor(options) { | |
Object.assign(this, options); | |
} | |
static create(options) { | |
return new this(options); | |
} | |
findRecord() { | |
return Promise.resolve({ | |
data: { | |
type: 'person', | |
id: '1', | |
attributes: { name: 'Chris' }, | |
relationships: { | |
father: { | |
data: null, | |
links: { | |
related: './person/1/father/' | |
} | |
} | |
} | |
} | |
}); | |
} | |
findBelongsTo() { | |
return new Promise(resolve => { | |
setTimeout(resolve, 3000); | |
}).then(() => { return { | |
data: { | |
type: 'person', | |
id: '2', | |
attributes: { name: 'John' }, | |
/* | |
relationships: { | |
child: { | |
data: { | |
type: 'person', id: '1' | |
} | |
} | |
} | |
*/ | |
} | |
}}); | |
} | |
} |
This file contains 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 Twiddle', | |
findUser() { | |
let store = this.get('store'); | |
return store.findRecord('person', '1') | |
.then(person => { | |
this.set('user', person); | |
let father = person.belongsTo('father').reload(); | |
return father; | |
}); | |
}, | |
init() { | |
this._super(...arguments); | |
this.findUser(); | |
} | |
}); |
This file contains 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 Ember from 'ember'; | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
export default Model.extend({ | |
name: attr(), | |
father: belongsTo('person', { | |
async: false, | |
inverse: 'child' | |
}), | |
child: belongsTo('person', { | |
async: false, | |
inverse: 'father' | |
}), | |
}); |
This file contains 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 MySerializer { | |
constructor(options) { | |
Object.assign(this, options); | |
} | |
static create(options) { | |
return new this(options); | |
} | |
normalizeResponse(_, __, data) { return data; } | |
} |
This file contains 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.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": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.8.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment