From b6234cb9434b5bd6dffccf72ec99798da81a302b Mon Sep 17 00:00:00 2001 From: Dekel Barzilay Date: Fri, 11 Oct 2019 22:27:48 +0300 Subject: [PATCH] - Changed `countDistinct` to be used only with `joinRelation` operator - Bumped version to 4.4.3 --- package-lock.json | 2 +- package.json | 2 +- src/index.js | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index c77498f..b70c6f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "feathers-objection", - "version": "4.4.2", + "version": "4.4.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 101219e..e1bc12a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "feathers-objection", "description": "A service plugin for ObjectionJS an ORM based on KnexJS", - "version": "4.4.2", + "version": "4.4.3", "homepage": "https://github.com/feathersjs-ecosystem/feathers-objection", "keywords": [ "feathers", diff --git a/src/index.js b/src/index.js index fc7cfc6..8bfaf2e 100644 --- a/src/index.js +++ b/src/index.js @@ -349,10 +349,15 @@ class Service extends AdapterService { if (count) { const idColumns = Array.isArray(this.id) ? this.id.map(idKey => `${this.Model.tableName}.${idKey}`) : [`${this.Model.tableName}.${this.id}`]; - const countQuery = this._createQuery(params) - .skipUndefined() - .joinRelation(query.$joinRelation) - .countDistinct({ total: idColumns }); + const countQuery = this._createQuery(params); + + if (query.$joinRelation) { + countQuery + .joinRelation(query.$joinRelation) + .countDistinct({ total: idColumns }); + } else { + countQuery.count({ total: idColumns }); + } this.objectify(countQuery, query);