Skip to content

Instantly share code, notes, and snippets.

@sdhull
Last active June 30, 2018 04:11
Show Gist options
  • Save sdhull/9fa7c8bc250032994b6e01c470ed30b3 to your computer and use it in GitHub Desktop.
Save sdhull/9fa7c8bc250032994b6e01c470ed30b3 to your computer and use it in GitHub Desktop.
ED 3.1.1 bug repro
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
import { inject as service } from '@ember/service';
export default Ember.Controller.extend({
store: service(),
actions: {
addItem(event) {
event.preventDefault();
let item = this.store.createRecord('item', {order: this.order});
item.save().then((itm) => {
console.log('saved the item!', itm);
});
}
},
});
let id = 0;
export default function() {
window.server = this;
this.post('/orders', function (schema, request) {
id = id + 1;
const resp = {
"data": {
"attributes": {id},
"id": id.toString(),
"type": "order"
}
}
console.log('creating order id: ', id);
return resp;
});
this.post('/items', function (schema, request) {
id = id + 1;
const resp = {
"data": {
"attributes": {id},
"relationships":{"order":{"data":{"type":"orders","id":"1"}}},
"id": id.toString(),
"type": "item"
}
}
console.log('creating item id: ', id);
console.log(request);
return resp;
});
};
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
order: belongsTo('order', {inverse: 'items'}),
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
items: hasMany('item', {inverse: 'order'}),
});
import Ember from 'ember';
export default Ember.Route.extend({
setupController(controller, model) {
this._super(controller, model);
let order = this.store.createRecord('order');
order.save();
controller.set('order', order);
},
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
Yo
<a href onclick={{action 'addItem'}}>
Click here to add an item
</a>
<h1>Order id: {{order.id}}</h1>
<ol>
{{#each order.items as |item|}}
<li>item id: {{item.id}}; item internal model id: {{item._internalModel.id}}</li>
{{/each}}
</ol>
{
"version": "0.15.0",
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"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.1.2",
"ember-template-compiler": "3.1.2",
"ember-testing": "3.1.2"
},
"addons": {
"ember-data": "3.1.1",
"ember-cli-mirage": "0.2.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment