Forked from YoranBrondsema/adapters.application.js
Last active
August 30, 2018 01:03
-
-
Save Subtletree/ea43ef1f2d5e6c8abe73fd5376d9c423 to your computer and use it in GitHub Desktop.
Non-async relationship bug (3.2.1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Adapter from "ember-data/adapters/json-api"; | |
export default Adapter.extend(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function returnJSON(status, body) { | |
return json(...arguments); | |
}; | |
export function json(status, body) { | |
if (arguments.length === 1) { | |
body = status; | |
status = 200; | |
} | |
return [ | |
status, | |
{ "Content-Type": "application/json" }, | |
JSON.stringify(body) | |
]; | |
}; | |
export const server = new Pretender(); | |
export function initialize() { | |
server.handledRequest = function(verb, path, request) { | |
console.log(`handled request to ${verb} ${path}`); | |
} | |
server.unhandledRequest = function(verb, path, request) { | |
console.log(`undhandled request ${verb} ${path}`); | |
} | |
}; | |
export default { | |
name: 'pretender', | |
initialize | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
post: DS.belongsTo('post'), | |
text: DS.attr('string') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
comments: DS.hasMany('comment', { async: false }), | |
name: DS.attr('string') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import { server, json } from '../initializers/pretender'; | |
server.map(function() { | |
this.get('/posts/1', function(request) { | |
if (request.queryParams.include) { | |
return json({ | |
data: { | |
id: 1, | |
type: 'post', | |
attributes: { | |
name: "Mark Twain" | |
}, | |
relationships: { | |
comments: { | |
data: [{ | |
id: 1, | |
type: 'comment' | |
}], | |
links: { | |
related: '/posts/1/comments' | |
} | |
} | |
} | |
}, | |
included: [ | |
{ | |
id: 1, | |
type: 'comment', | |
attributes: { | |
text: "Bla" | |
}, | |
relationships: { | |
post: { | |
data: { | |
id: 1, | |
type: 'post' | |
}, | |
links: { | |
related: '/comments/1/post' | |
} | |
} | |
} | |
} | |
] | |
}); | |
} else { | |
return json({ | |
data: { | |
id: 1, | |
type: 'post', | |
attributes: { | |
name: "Mark Twain" | |
}, | |
relationships: { | |
comments: { | |
links: { | |
related: '/posts/1/comments' | |
} | |
} | |
} | |
} | |
}); | |
} | |
}); | |
}); | |
export default Ember.Route.extend({ | |
model() { | |
return this.get('store').findRecord('post', 1, { include: 'comments'}); | |
}, | |
afterModel(post) { | |
this.get('store').findRecord('post', 1); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Serializer from "ember-data/serializers/json-api"; | |
export default Serializer.extend(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.10.4", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "3.1.2", | |
"ember-template-compiler": "3.2.2", | |
"route-recognizer": "https://rawgit.com/tildeio/route-recognizer/56f5fcec6ae58d8e86b5dc77609809fb91198142/dist/route-recognizer.js", | |
"FakeXMLHttpRequest": "https://rawgit.com/pretenderjs/FakeXMLHttpRequest/23c3a96b5b24f1bfe595867437e4f128a29c2840/fake_xml_http_request.js", | |
"pretender": "https://rawgit.com/pretenderjs/pretender/c6de9afe18b1472aded2592f5a80ad9a26a0e262/pretender.js" | |
}, | |
"addons": { | |
"ember-data": "3.2.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment