Skip to content

Instantly share code, notes, and snippets.

@sly7-7
Last active March 10, 2020 09:04
Show Gist options
  • Save sly7-7/fd9a41b63bc96b2ae43118bad001a224 to your computer and use it in GitHub Desktop.
Save sly7-7/fd9a41b63bc96b2ae43118bad001a224 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
store: Ember.inject.service(),
get firstThing() {
return this.model.hasMany('things').value().firstObject;
},
actions: {
updateUser: function() {
this.store.push({
data: {
type: 'user',
id: 1,
relationships: {
things: {data:[{
type: 'thing',
id: 2
}]}
}
},
included: [{
type: 'thing',
id: 2
}]
})
}
}
});
import Model from 'ember-data/model';
/*
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
*/
export default Model.extend({
});
import Model from 'ember-data/model';
import { hasMany } from 'ember-data/relationships';
export default Model.extend({
things: hasMany('thing')
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.push({
data: {
type: 'user',
id: '1',
relationships: {
things: {data: [{
type: 'thing',
id: '1'
}]}
}
},
included: [{
type: 'thing',
id: '1'
}]
})
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{model.id}}
{{this.firstThing.id}}
<button {{action 'updateUser'}}>Click</button>
<br>
<br>
{
"version": "0.16.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.14.3",
"ember-template-compiler": "3.14.3",
"ember-testing": "3.14.3"
},
"addons": {
"ember-data": "3.14.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment