-
-
Save karellm/c5d8fda98c4bd06d2221e3e137e8c5b4 to your computer and use it in GitHub Desktop.
Relationships
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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
title: DS.attr('string'), | |
author: DS.belongsTo('author') | |
}); |
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 config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('author', { path: '/:authorId' }, function () { | |
this.route('books', { path: '/' }); | |
}); | |
}); | |
export default Router; |
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('/authors', function() { | |
return json({ | |
data: [ | |
{ | |
id: 1, | |
type: 'author', | |
attributes: { | |
name: 'Author 1' | |
}, | |
relationships: { | |
books: { | |
links: { | |
related: '/authors/1/books' | |
} | |
} | |
} | |
}, | |
{ | |
id: 2, | |
type: 'author', | |
attributes: { | |
name: 'Author 2' | |
}, | |
relationships: { | |
books: { | |
links: { | |
related: '/authors/2/books' | |
} | |
} | |
} | |
}, | |
{ | |
id: 3, | |
type: 'author', | |
attributes: { | |
name: 'Author 3' | |
}, | |
relationships: { | |
books: { | |
links: { | |
related: '/authors/3/books' | |
} | |
} | |
} | |
} | |
] | |
}); | |
}); | |
}); | |
export default Ember.Route.extend({ | |
model: function() { | |
return this.get('store').findAll('author'); | |
} | |
}); |
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": "2.11.0", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.10.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": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment