Skip to content

Instantly share code, notes, and snippets.

@hvgotcodes
Created February 16, 2018 15:40
Show Gist options
  • Save hvgotcodes/3e680ca9dfe0f870891f1aeb9cf024d0 to your computer and use it in GitHub Desktop.
Save hvgotcodes/3e680ca9dfe0f870891f1aeb9cf024d0 to your computer and use it in GitHub Desktop.
Unload Record Oops
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
removeChild() {
this.model.get('children.firstObject').unloadRecord()
}
}
});
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('parent')
});
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('child')
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
const p1 = this.store.createRecord('parent', {
id: 'p1'
});
const c1 = this.store.createRecord('child', {
id: 'c1',
parent: p1
});
const c2 = this.store.createRecord('child', {
id: 'c2',
parent: p1
});
return p1;
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<div>
Has {{model.children.length}} children
</div>
<button {{action 'removeChild'}}>Remove child</button>
{
"version": "0.13.0",
"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