diff --git a/app/models/post.js b/app/models/post.js new file mode 100644 index 0000000..c05ee8d --- /dev/null +++ b/app/models/post.js @@ -0,0 +1,5 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + user: DS.belongsTo() +}); diff --git a/app/models/user.js b/app/models/user.js index 4a2b700..935a324 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -1,5 +1,7 @@ import DS from 'ember-data'; export default DS.Model.extend({ - name: DS.attr() + name: DS.attr(), + + posts: DS.hasMany() }); diff --git a/app/routes/application.js b/app/routes/application.js index 23b4c6e..901f6aa 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -3,7 +3,7 @@ import Route from '@ember/routing/route'; export default Route.extend({ model() { - return this.store.findRecord('user', 1); + return this.store.findRecord('user', 1).catch(console.error); } }); diff --git a/mirage/scenarios/default.js b/mirage/scenarios/default.js index 226de17..83241bd 100644 --- a/mirage/scenarios/default.js +++ b/mirage/scenarios/default.js @@ -1,5 +1,6 @@ export default function(server) { - server.create('user', { name: 'Yehuda' }); + let user = server.create('user', { name: 'Yehuda' }); + server.createList('post', 3, { user }); } diff --git a/mirage/serializers/application.js b/mirage/serializers/application.js index 6d47a36..da28a77 100644 --- a/mirage/serializers/application.js +++ b/mirage/serializers/application.js @@ -1,4 +1,17 @@ import { JSONAPISerializer } from 'ember-cli-mirage'; export default JSONAPISerializer.extend({ + alwaysIncludeLinkageData: true, + + keyForAttribute(attr) { + return attr.underscore(); + }, + + keyForRelationship(modelName) { + return modelName.underscore(); + }, + + keyForModel() { return 'user'; }, + + typeKeyForModel(model) { return model.modelName; }, });