Skip to content

Instantly share code, notes, and snippets.

@Kilowhisky
Created June 27, 2016 19:10
Show Gist options
  • Save Kilowhisky/8058c9349db3e850115b6186ee1ae61e to your computer and use it in GitHub Desktop.
Save Kilowhisky/8058c9349db3e850115b6186ee1ae61e to your computer and use it in GitHub Desktop.
Query Record Relationships Error
import DS from 'ember-data';
export default DS.RESTAdapter.extend({});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
myset: belongsTo('myset'),
createdDate: attr('date'),
settings: attr()
});
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('string'),
revisionLatest: belongsTo('myset-revision')
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('set-edit', { path: '/edit/:set_id/:revision_id' });
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
init(){
this._super(...arguments);
$.mockjax({
url: '/mysets',
responseText: [
{
id: "1",
name: "Test 1",
revisionLatest: "2"
}
]
});
$.mockjax({
url: '/mysets/1',
responseText: {
id: "1",
name: "Test 1",
revisionLatest: "2"
}
});
$.mockjax({
url: '/mysetRevisions/2',
responseText: {
id: "2",
myset: "1",
createdDate: "2016-06-27T16:11:43.4970000Z"
}
});
$.mockjax({
url: '/mysetRevisions',
data: {
includeSettings: true,
revision: 2
},
responseText: {
id: "2",
myset: "1",
createdDate: "2016-06-27T16:11:43.4970000Z",
settings: {
setting1: "value"
}
}
});
$.mockjax({
url: '/mysetRevisions',
data: {
includeSettings: true,
revision: 1
},
responseText: {
id: "1",
myset: "1",
createdDate: "2016-06-27T16:11:43.4970000Z",
settings: {
setting1: "value1"
}
}
});
$.mockjax({
url: '/mysetRevisions',
data: {
setId: 1
},
responseText: [
{ id: "1", myset: "1", createdDate: "2016-06-27T15:11:43.4970000Z" },
{ id: "2", myset: "1", createdDate: "2016-06-27T16:11:43.4970000Z" }
]
});
},
model(){
return this.store.findAll('myset')
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model(params){
return Ember.RSVP.hash({
set: this.store.findRecord('myset', params.set_id),
revision: this.store.queryRecord('myset-revision', {
revision: params.revision_id,
includeSettings: true
}),
revisions: this.store.query('myset-revision', { setId: params.set_id })
});
}
});
import DS from 'ember-data';
export default DS.JSONSerializer.extend({});
<h1>ember data bug</h1>
<h3>Set #1 revisions</h3>
{{#link-to 'set-edit' 1 1}}Revision 1{{/link-to}}
{{#link-to 'set-edit' 1 2}}Revision 2{{/link-to}}
<div>
{{outlet}}
</div>
<h3>Editing Set: {{model.set.name}}; Revision: {{model.revision.id}}</h3>
<div>ModelRevisionCreated: {{model.revision.createdDate}}</div>
<div>SetLatestRevision: {{model.set.revisionLatest.id}}</div>
<div>Editing Revision ID: {{model.revision.id}}</div>
<h3> Historical revisions </h3>
{{#each model.revisions as |revision|}}
<div>{{#link-to 'set-edit' revision.myset.id revision.id}}View Revision: {{revision.id}}{{/link-to}}</div>
{{/each}}
{
"version": "0.10.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.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0",
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment