Skip to content

Instantly share code, notes, and snippets.

@MichalBryxi
Forked from Gaurav0/application.route.js
Last active July 25, 2017 14:48
Show Gist options
  • Save MichalBryxi/cde3718f464cf3a7ebe41b6ec7e71d4e to your computer and use it in GitHub Desktop.
Save MichalBryxi/cde3718f464cf3a7ebe41b6ec7e71d4e to your computer and use it in GitHub Desktop.
ember-data duplicate IDs
import Adapter from "ember-data/adapters/rest";
export default Adapter.extend();
import Ember from 'ember';
export default Ember.Route.extend({
init() {
this._super(...arguments);
$.mockjax({
url: '/mocks',
responseText: {
"mock": [
{
id: 1,
text: "foo"
},
{
id: 1,
text: "second foo"
},
{
id: 3,
text: "bar"
}
]
}
});
},
model() {
return this.store.query('mock', {});
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
peek: Ember.computed(function () {
return this.store.peekAll('mock');
})
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
text: DS.attr('string')
});
<h1>Welcome to {{appName}}</h1>
<h2>Query</h2>
<code>
this.store.query('mock', {});
</code>
<ul>
{{#each model as |mock|}}
<li>{{mock.id}}: {{mock.text}}</li>
{{/each}}
</ul>
<h2>Subsequent peek</h2>
<code>
this.store.peekAll('mock');
</code>
<ul>
{{#each peek as |mock|}}
<li>{{mock.id}}: {{mock.text}}</li>
{{/each}}
</ul>
{
"version": "0.4.8",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-data": "2.12.1",
"ember-template-compiler": "2.12.0",
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment