Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gustaff-weldon/80d068eaafa9b8c6a5c06e512cbd026a to your computer and use it in GitHub Desktop.
Save gustaff-weldon/80d068eaafa9b8c6a5c06e512cbd026a to your computer and use it in GitHub Desktop.
broken relationship
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this.set('parent', this.store.createRecord('parent', {name:'foo'}))
},
actions: {
addNewChild() {
console.log(`@ foo`)
const child = this.store.createRecord('child', {parent: this.parent})
this.set('child', child)
},
unloadLastChild() {
if (this.child) {
// Commented out and it is broken somehow
// this.child.set('parent', null)
this.child.unloadRecord()
this.set('child', null)
}
}
}
});
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'),
name: attr('string')
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{parent.children.length}}
<button onclick={{action "addNewChild"}}>Add</button>
<button onclick={{action "unloadLastChild"}}>Unload last child</button>
<br>
<br>
{
"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.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment