Last active
May 9, 2018 22:57
-
-
Save GCheung55/951dbd66552c663492da4b578638f397 to your computer and use it in GitHub Desktop.
Demonstrate issue with loading/unloading record with 1-1 relationships
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'; | |
import RSVP from 'rsvp'; | |
export default DS.RESTAdapter.extend({ | |
deleteRecord() { | |
const response = this.handleResponse( | |
204, | |
{}, | |
{}, | |
undefined | |
); | |
return RSVP.resolve(response); | |
} | |
}); |
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'; | |
import RSVP from 'rsvp'; | |
export default DS.RESTAdapter.extend({ | |
deleteRecord() { | |
const response = this.handleResponse( | |
204, | |
{}, | |
{}, | |
undefined | |
); | |
return RSVP.resolve(response); | |
} | |
}); |
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 Twiddle', | |
actions: { | |
destroy(fooModel) { | |
const store = this.get('store'); | |
const bar = fooModel.get('bar'); | |
/** | |
* Without this push to null foo data, | |
* creating a new bar record with same ID will fail | |
*/ | |
store.push({ | |
data: { | |
type: 'bar', | |
id: bar.get('id'), | |
attributes: {}, | |
relationships: { | |
foo: { | |
data: null | |
} | |
} | |
} | |
}); | |
bar.destroyRecord().then((resp) => { | |
console.log(resp); | |
store.unloadRecord(bar); | |
}); | |
}, | |
pushRecord(fooModel) { | |
const store = this.get('store'); | |
const bar = store.createRecord('bar', {id: 1}); | |
fooModel.set('bar', bar); | |
console.log(store.peekRecord('bar', 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({ | |
foo: belongsTo('foo', {async: false}) | |
}); |
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({ | |
bar: belongsTo('bar', {async: false}) | |
}); |
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({ | |
model() { | |
const store = this.get('store'); | |
store.push({ | |
data: [{ | |
type: 'foo', | |
id: 1, | |
attributes: {}, | |
relationships: { | |
bar: { | |
data: {id: 1, type: 'bar'} | |
} | |
} | |
}, { | |
type: 'bar', | |
id: 1, | |
attributes: {}, | |
relationships: { | |
foo: { | |
data: {id: 1, type: 'foo'} | |
} | |
} | |
}] | |
}); | |
return store.peekRecord('foo', 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
{ | |
"version": "0.13.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.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment