Skip to content

Commit

Permalink
fix: returns undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin committed Dec 27, 2019
1 parent 37a9442 commit c9be041
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function belongsToRelationAcceptance(
expect(result).to.deepEqual(shipment);
});

it('returns an empty array if the source instance does not have the foreign key', async () => {
it('returns undefined if the source instance does not have the foreign key', async () => {
await shipmentRepo.create({
name: 'Tuesday morning shipment',
});
Expand All @@ -102,7 +102,7 @@ export function belongsToRelationAcceptance(
description: 'Order that is shipped Tuesday morning',
});
const result = await orderRepo.shipment(order.id);
expect(result).to.deepEqual([]);
expect(result).to.be.undefined();
});

it('throws EntityNotFound error when the related model does not exist', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ export function createBelongsToAccessor<
const primaryKey = meta.keyTo;
const sourceModel = await sourceRepository.findById(sourceId);
const foreignKeyValue = sourceModel[foreignKey as keyof Source];
// different dbs use different empty values
if (foreignKeyValue === undefined || foreignKeyValue === null) {
return ([] as unknown) as Target;
// workaround to check referential integrity.
// should be removed once the memory connector ref integrity is done
if (!foreignKeyValue) {
return (undefined as unknown) as Target;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const constraint: any = {[primaryKey]: foreignKeyValue};
Expand Down

0 comments on commit c9be041

Please sign in to comment.