Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix withRelated not always grouping properly for binary IDs #1918
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
This should be a minor, non-breaking change that only changes local behavior to the relationships
When grouping relationships and building the collection map, convert Buffer IDs to string keys
Current PR Issues
no known issues with making this change...
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.
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.