-
Notifications
You must be signed in to change notification settings - Fork 577
Fix withRelated not always grouping properly for binary IDs #1918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix withRelated not always grouping properly for binary IDs #1918
Conversation
- When grouped relations, convert Buffers to hex strings to use as the mapping key
ricardograca
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks simple enough but it needs tests to verify the correct behavior of the fix, and to ensure that this bug doesn't get introduced again in the future.
|
I actually wrote a unit test, but found that the problem was bigger than I initially thought... it basically boils down to code something like this: There are several places in the code where the ID is assumed to be used as a unique object key. However, with Buffers, this doesn't always work because they get converted to a string representation which may have collisions. I now found that the collection I could go further and update this PR, but I thought I'd ask if you have any other thoughts first @ricardograca ? |
|
I don't even understand how/why Buffers can be used as keys, so the fact that it more or less works at all is new to me. You can do whatever you need to make your use case work as long as that doesn't break any of the existing functionality and tests are included. If the extra fixes you mention are not immediately being required to you it's OK if you don't fix them. |
… collection keying again - Added a collection test with binary IDs
…/related-binary-ids # Conflicts: # test/integration/relations.js
|
OK - I've added tests and fixes to collections. If you need more details or changes I'm happy to do so @ricardograca . Thanks for your quick responses!! |
ricardograca
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just needs to address the two small issues I mentioned, and then I'll merge. I'm still waiting for another big PR to be merged, so this one will probably only go after that one: #1848.
- Remove 'debug:true' from unit test
|
Changes made - thanks for catching the |
ricardograca
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will merge after #1848 is merged, since I already spent a lot of time fixing merge conflicts in that one and if there are any in this afterwards they will certainly be easier to fix.
Introduction
When I was working with a larger dataset that uses binary IDs, I found that sometimes the 'withRelated' was returning incorrect results. The database queries were correct with retrieving the relationships, but they were being incorrectly assigned to the primary collection. In the end, I found that if I changed the grouping to convert
Buffertypes to strings, then all of my relationships were set correctly.Motivation
This should be a minor, non-breaking change that only changes local behavior to the relationships
eagerPairmethod.Proposed solution
When grouping relationships and building the collection map, convert Buffer IDs to string keys
Current PR Issues
no known issues with making this change...
Alternatives considered
I debated using a local parse method in my model, but thought that this would fix it more at the source rather than requiring me to add a parse method to all of my models.