Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Nov 6, 2021
1 parent d8ca98a commit cef73c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 2 additions & 4 deletions lib/relations/RelationOwner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions tests/integration/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit cef73c4

Please sign in to comment.