8000 fix(Collection): 'get' to return undefined when item id is not provid… · correct-js/js-data@c109e57 · GitHub
[go: up one dir, main page]

Skip to content

Commit c109e57

Browse files
ivanvoznyakovskyjmdobry
authored andcommitted
fix(Collection): 'get' to return undefined when item id is not provided (js-data#457)
1 parent c15dba3 commit c109e57

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/Collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ export default Component.extend({
511511
* @returns {(Object|Record)} The record with the given id.
512512
*/
513513
get (id) {
514-
const instances = this.query().get(id).run()
514+
const instances = id === undefined ? [] : this.query().get(id).run()
515515
return instances.length ? instances[0] : undefined
516516
},
517517

test/unit/collection/get.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ describe('Collection#get', function () {
55
const user = this.UserCollection.add({ id: 1 })
66
assert(this.UserCollection.get(1) === user, 'should get the user from the collection')
77
assert(!this.UserCollection.get(2), 'should return undefined if the item is not in the collection')
8+
assert(!this.UserCollection.get(), 'should return undefined if item id is not provided')
89
})
910
})

0 commit comments

Comments
 (0)
0