Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Last active August 15, 2018 15:50
Show Gist options
  • Save phillipkregg/6a3ec4111dda1698b7f86e8b4d10ccb3 to your computer and use it in GitHub Desktop.
Save phillipkregg/6a3ec4111dda1698b7f86e8b4d10ccb3 to your computer and use it in GitHub Desktop.
Store Test Save Model
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
persons: Ember.computed('store', function() {
return this.get('store').peekAll('person');
}),
actions: {
addPerson() {
debugger;
this.get('store').createRecord('person', {
name: 'Tom'
})
}
}
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
name: attr()
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').peekAll('person');
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{#each persons as |person|}}
<li>{{person.name}}</li>
{{/each}}
{{outlet}}
<br>
<br>
<button {{action 'addPerson'}}>Add Person</button>
{
"version": "0.15.0",
"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.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment