Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Yan committed Jan 11, 2019
2 parents 2453cea + abcfa36 commit 18a123e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "objection-filter",
"version": "2.0.0",
"version": "2.1.0",
"description": "A filter module for objection.js",
"main": "./dist/index.js",
"engines": {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/FilterQueryBuilder.js
Expand Up @@ -140,7 +140,9 @@ const buildAggregation = function(aggregation, builder, utils) {
throw new Error(`Must specify "field" with [${type}] aggregation`);
}

const baseIdColumn = Model.tableName + '.' + Model.idColumn;
const baseIdColumn = typeof Model.idColumn === 'string'
? Model.tableName + '.' + Model.idColumn
: Model.idColumn.map(idColumn => Model.tableName + '.' + idColumn);

// When joining the filter query, the base left-joined table is aliased
// as the full relation name joined by the : character
Expand Down
20 changes: 19 additions & 1 deletion test/aggregation.test.js
Expand Up @@ -25,12 +25,13 @@ const fillArray = function(counts = [], objects = []) {
describe('aggregation', function () {
_.each(testUtils.testDatabaseConfigs, function (knexConfig) {
describe(knexConfig.client, function() {
let session, Person, Animal;
let session, Person, Animal, MovieVersion;

before(function () {
session = testUtils.initialize(knexConfig);
Person = session.models.Person;
Animal = session.models.Animal;
MovieVersion = session.models.MovieVersion;
});

before(function () {
Expand Down Expand Up @@ -212,6 +213,23 @@ describe('aggregation', function () {
});
});

describe('composite ids', function() {
it('should aggregate if root model has composite id', async function() {
const result = await buildFilter(MovieVersion)
.build({
eager: {
$aggregations: [
{
type: 'count',
relation: 'movie'
}
]
}
});
result.map(item => item.count).should.deep.equal(fillArray([100], [1]));
});
});

describe('multiple aggregations', function() {
it('should apply multiple counts', async () => {
const result = await buildFilter(Animal)
Expand Down

0 comments on commit 18a123e

Please sign in to comment.