Skip to content

Commit

Permalink
fixes Vincit#2135
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Nov 5, 2021
1 parent bd16a7e commit 33a03cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/relations/RelationOwner.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ class RelationOwner {
if (values) {
builder.whereInComposite(relatedRefs, values);
} else {
builder.where(false);
builder.resolve([]);
}
} else {
builder.where(false);
builder.resolve([]);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/integration/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -2410,6 +2410,18 @@ module.exports = (session) => {
});
});

it('should return undefined if the model has no parents', async () => {
const parent = await Model1.query().findById(2);

const result1 = await parent.$relatedQuery('model1Relation1').debug();
expect(result1).to.be.equal(undefined);

const result2 = await Model1.relatedQuery('model1Relation1')
.for(Model1.relatedQuery('model1Relation1').for(parent))
.debug();
expect(result2).to.eql([]);
});

describe('knex methods', () => {
it('.select()', () => {
return parent1
Expand Down

0 comments on commit 33a03cf

Please sign in to comment.