From cef73c4525edcbb48399785756fecefb050d01bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Sat, 6 Nov 2021 17:32:25 +0200 Subject: [PATCH] cleanup --- lib/relations/RelationOwner.js | 6 ++---- tests/integration/find.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/relations/RelationOwner.js b/lib/relations/RelationOwner.js index 9e058cd4d..a24858816 100644 --- a/lib/relations/RelationOwner.js +++ b/lib/relations/RelationOwner.js @@ -71,12 +71,10 @@ class RelationOwner { if (values) { builder.whereInComposite(relatedRefs, values); } else { - builder.where(false); - builder.resolve([]); + builder.where(false).resolve([]); } } else { - builder.where(false); - builder.resolve([]); + builder.where(false).resolve([]); } return builder; diff --git a/tests/integration/find.js b/tests/integration/find.js index 8654fd6b7..cd76418fc 100644 --- a/tests/integration/find.js +++ b/tests/integration/find.js @@ -2400,16 +2400,21 @@ module.exports = (session) => { }); }); - it('should return undefined if the model has no parents', async () => { + it('should return undefined if the result is empty', async () => { const parent = await Model1.query().findById(2); const result1 = await parent.$relatedQuery('model1Relation1'); expect(result1).to.be.equal(undefined); - const result2 = await Model1.relatedQuery('model1Relation1').for( - Model1.relatedQuery('model1Relation1').for(parent) + const result2 = await Model1.query().from( + Model1.relatedQuery('model1Relation1').for(parent).as('model1') ); expect(result2).to.eql([]); + + const result3 = await Model1.query().from( + Model1.relatedQuery('model1Relation1').for(parent.id).as('model1') + ); + expect(result3).to.eql([]); }); describe('knex methods', () => {