Skip to content

Instantly share code, notes, and snippets.

@luxzeitlos
Created April 19, 2017 00:02
Show Gist options
  • Save luxzeitlos/26158f912194f24d198ff5d3a7309224 to your computer and use it in GitHub Desktop.
Save luxzeitlos/26158f912194f24d198ff5d3a7309224 to your computer and use it in GitHub Desktop.
New Twiddle
import DS from 'ember-data';
export default DS.JSONAPIAdapter.extend({
findRecord() {
return {
data: {
type: 'parent-object',
id: '2',
attributes: {
name: 'foo'
}
}
};
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
foo() {
this.store.findRecord('parent-object', 2).then(parent => {
const child = this.store.createRecord('child-object');
parent.get('children').pushObject(child);
alert(child.get('parent.name'));
});
},
foo2() {
this.store.findRecord('parent-object', 2).then(parent => {
const child = this.store.createRecord('child-object');
child.set('parent', parent);
alert(parent.get('children.length'));
});
}
}
});
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
parent: DS.belongsTo('parent-object')
});
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
children: DS.hasMany('child-object')
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<button onclick={{action 'foo'}}>foo</button>
<button onclick={{action 'foo2'}}>foo2</button>
<br>
<br>
{
"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.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment