Skip to content

Commit 12c4ffb

Browse files
Merge pull request #21 from vjoao/master
Find method respects relationships, fixes #13
2 parents 4061a9f + 5af1baf commit 12c4ffb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Model.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export default class Model extends StaticModel {
167167
return this
168168
}
169169

170-
/**
170+
/**
171171
* Result
172172
*/
173173

@@ -189,8 +189,8 @@ export default class Model extends StaticModel {
189189
if (identifier === undefined) {
190190
throw new Error('You must specify the param on find() method.')
191191
}
192-
193-
let url = `${this.baseURL()}/${this.resource()}/${identifier}${this._builder.query()}`
192+
let base = this._fromResource || `${this.baseURL()}/${this.resource()}`
193+
let url = `${base}/${identifier}${this._builder.query()}`
194194

195195
return this.request({
196196
url,

tests/model.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ describe('Model methods', () => {
325325
posts = await user.posts().get()
326326
})
327327

328+
test('a request from hasMany() with a find() hits right resource', async () => {
329+
let user
330+
let post
331+
332+
axiosMock.onAny().reply((config) => {
333+
expect(config.method).toEqual('get')
334+
expect(config.url).toEqual('http://localhost/users/1/posts/1')
335+
return [200, {}]
336+
})
337+
338+
user = new User({ id: 1 })
339+
post = await user.posts().find(1)
340+
})
341+
328342
test('a request hasMany() method returns a array of Models', async () => {
329343

330344
axiosMock.onGet('http://localhost/users/1/posts').reply(200, postsResponse)

0 commit comments

Comments
 (0)