Skip to content

Conversation

@deepakrkris
Copy link
Contributor

@deepakrkris deepakrkris commented Mar 4, 2020

fixes #4372

fix querying related entities with null keys and add tests to repository-test

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

});

let results = await orderRepo.find({include: [{relation: 'customer'}]});
expect(results.length).to.equal(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we trying to fix in the PR? I didn't see the code changes, and new added test doesn't seem to test the null fk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @agnes512, I moved in with only the tests first to check all the datasources that fail for this condition. I am adding the code changes now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have opened a draft PR, sorry about the false alarm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agnes512 the new tests do check for null fk , because the order 'Dine in' has no customer Id.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh haha I see. Sorry that I got the notification and just reviewed it.

And I have a few questions. I checked other tests in this file, the test in #L 97 checks the case that source instance does not have the foreign key. Why is that one passing before the changes? Is the bug caused by the inclusion? If so, I think file belongs-to.inclusion-resolver.relation.acceptance.ts fits this test more. From my understanding, order.customer(order.id) is different from order.find({include customer}, because the later one uses the inclusion resolver, where the problem lies in. It'd also be better if we can check content of result to see if there is only one instance has the related model.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agnes512 the other test passes because it directly queries the target relation. You are right, I will move this test to the inclusion resolver tests. it suites better there.

@deepakrkris deepakrkris changed the title fix: query entities with null foreign key fix: filter null keys when including belongs-to relations in queries Mar 5, 2020
@deepakrkris deepakrkris self-assigned this Mar 5, 2020
@hacksparrow
Copy link
Contributor

Does this PR make the behavior of all the connectors uniform now? Is there any difference between Postgres and others? If yes, we should add the details on the website docs.

@deepakrkris
Copy link
Contributor Author

Does this PR make the behavior of all the connectors uniform now? Is there any difference between Postgres and others? If yes, we should add the details on the website docs.

@hacksparrow this is not a behavioral change, users will not see any difference in querying. It only removes null keys before querying a relation.

Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@deepakrkris deepakrkris merged commit cccb37f into master Mar 6, 2020
@deepakrkris deepakrkris deleted the fix4372 branch March 6, 2020 21:17
targetRepo,
targetKey,
deduplicate(sourceIds),
dedupedSourceIds.filter(e => e),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have a valid id value that's not truthy? For example, I can imagine 0 being a valid primary key. Your condition will filter such value out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Belongs-To relation tries to resolve for foreign key NULL

6 participants