diff --git a/app/routes/posts/detail/comments.js b/app/routes/posts/detail/comments.js index deaefb1..a5e8821 100644 --- a/app/routes/posts/detail/comments.js +++ b/app/routes/posts/detail/comments.js @@ -3,6 +3,7 @@ import Route from '@ember/routing/route'; export default Route.extend({ model() { let post = this.modelFor('posts.detail'); - return this.store.findAll('comment', { adapterOptions: { parentResource: post } }); + // return this.store.findAll('comment', { adapterOptions: { parentResource: post } }); + return this.store.findSubAll(post, 'comment'); } }); diff --git a/app/routes/posts/detail/comments/detail.js b/app/routes/posts/detail/comments/detail.js index 478b3e6..6e58d20 100644 --- a/app/routes/posts/detail/comments/detail.js +++ b/app/routes/posts/detail/comments/detail.js @@ -3,6 +3,7 @@ import Route from '@ember/routing/route'; export default Route.extend({ model({ comment_id }) { let post = this.modelFor('posts.detail'); - return this.store.findRecord('comment', comment_id, { adapterOptions: { parentResource: post } }); + // return this.store.findRecord('comment', comment_id, { adapterOptions: { parentResource: post } }); + return this.store.findSubRecord(post, 'comment', comment_id); } }); diff --git a/app/services/store.js b/app/services/store.js new file mode 100644 index 0000000..e5b5cab --- /dev/null +++ b/app/services/store.js @@ -0,0 +1,17 @@ +import DS from 'ember-data'; + + +export default DS.Store.extend({ + findSubRecord(parentResource, resourceName, resourceId, options) { + options = options || {}; + options.adapterOptions = options.adapterOptions || {}; + Object.assign(options.adapterOptions, { parentResource }); + return this.findRecord(resourceName, resourceId, options); + }, + findSubAll(parentResource, resourceName, options) { + options = options || {}; + options.adapterOptions = options.adapterOptions || {}; + Object.assign(options.adapterOptions, { parentResource }); + return this.findAll(resourceName, options); + } +}); diff --git a/tests/unit/services/store-test.js b/tests/unit/services/store-test.js new file mode 100644 index 0000000..16923a6 --- /dev/null +++ b/tests/unit/services/store-test.js @@ -0,0 +1,12 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Service | store', function(hooks) { + setupTest(hooks); + + // Replace this with your real tests. + test('it exists', function(assert) { + let service = this.owner.lookup('service:store'); + assert.ok(service); + }); +});