Skip to content

Commit 4bafdc7

Browse files
committed
find getter: take union by ID instead of concat with tempsById
1 parent cca1c19 commit 4bafdc7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/service-module/service-module.getters.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { filterQuery, sorter, select } from '@feathersjs/adapter-commons'
99
import { globalModels as models } from './global-models'
1010
import _get from 'lodash/get'
1111
import _omit from 'lodash/omit'
12+
import _unionBy from 'lodash/unionBy'
1213

1314
const FILTERS = ['$sort', '$limit', '$skip', '$select']
1415
const OPERATORS = ['$in', '$nin', '$lt', '$lte', '$gt', '$gte', '$ne', '$or']
@@ -26,7 +27,7 @@ export default function makeServiceGetters() {
2627
// Set params.temps to true to include the tempsById records
2728
params.temps = params.hasOwnProperty('temps') ? params.temps : false
2829

29-
const { paramsForServer, whitelist } = state
30+
const { paramsForServer, whitelist, idField, tempIdField } = state
3031
const q = _omit(params.query || {}, paramsForServer)
3132
const customOperators = Object.keys(q).filter(
3233
k => k[0] === '$' && !defaultOps.includes(k)
@@ -39,7 +40,11 @@ export default function makeServiceGetters() {
3940
let values = _.values(state.keyedById)
4041

4142
if (params.temps) {
42-
values = values.concat(_.values(state.tempsById))
43+
values = _unionBy(
44+
values,
45+
_.values(state.tempsById),
46+
i => i[tempIdField] || i[idField]
47+
)
4348
}
4449

4550
values = values.filter(sift(query))

0 commit comments

Comments
 (0)