Skip to content

Instantly share code, notes, and snippets.

@jlami
Created May 9, 2017 12:25
Show Gist options
  • Select an option

  • Save jlami/8d2daa7a3509e00f59be3c3d6e2f3bff to your computer and use it in GitHub Desktop.

Select an option

Save jlami/8d2daa7a3509e00f59be3c3d6e2f3bff to your computer and use it in GitHub Desktop.
unloadRecord-breaks-2.13
import Ember from "ember";
import DS from "ember-data";
const {attr, hasMany} = DS;
export default DS.Model.extend({
posts: hasMany('post'),
name: attr('string'),
test: Ember.computed('posts.@each.name', function() {
console.group();
Ember.RSVP.resolve(this.get('posts')).then(posts => {
posts.forEach(p => {
console.log(p);
});
});
console.groupEnd();
return 'doingit';
}),
});
import Ember from "ember";
import DS from "ember-data";
const {attr, belongsTo} = DS;
export default DS.Model.extend({
author: belongsTo('author'),
name: attr('string'),
});
import Ember from 'ember';
export default Ember.Route.extend({
post2: null,
model() {
let author = this.store.createRecord('author', {name: 'Author'});
let post1 = this.store.createRecord('post', {name: 'Post 1', author: author});
this.post2 = this.store.createRecord('post', {name: 'Post 2', author: author});
return author;
},
actions: {
test() {
this.post2.unloadRecord();
},
},
});
{{model.name}} - {{model.test}}
<ul>
{{#each model.posts as |p|}}
<li>{{p.name}}</li>
{{/each}}
</ul>
<button {{action 'test'}}>Test</button>
{
"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