Support for polymorphic id_method_name - #17
Merged
Merged
Conversation
Collaborator
|
@aub, thanks for submitting this, it looks very clean. Do you mind changing the tests or adding a new one maybe? |
Contributor
Author
|
Hey @stas sorry for the holdup but I've added a couple of tests. Thanks! |
stas
approved these changes
Nov 20, 2019
| it 'inherits the id source' do | ||
| e = Employee.new | ||
| e.id = 2 | ||
| e.uuid = 'dfsdfsd' |
Collaborator
There was a problem hiding this comment.
@aub consider using SecureRandom.uuid to have valid realistic data in tests.
Collaborator
|
I'm pretty stoked to see this pulled over, and to see continued development on this incredible gem. I'll be contributing myself now that it's properly open sourced! |
Contributor
|
Sorry for the holdup on this. Yes - looks ok to me. I agree with the point about the UUID in the test, as a keyboard mash doesn't give the right signals in terms of code quality, but it's not a blocker. |
(cherry picked from commit 5791c356b894bd4e0338953721f121522e56defd) add specs (cherry picked from commit a25580a59cfda36af6de396b87e0767322e33d7e)
Contributor
Author
|
Ok, I changed it to use SecureRandom.uuid |
jopotts
approved these changes
Dec 3, 2019
Collaborator
|
Thank you very much @aub! |
BrianSigafoos
pushed a commit
to BrianSigafoos/fast_jsonapi
that referenced
this pull request
Dec 3, 2019
* fix id method bugs, add specs * Use SecureRandom.uuid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a duplicate of my PR against the Netflix project.
For polymorphic has_many relations, instead of getting the ids in a batch, the code loops over each object to get its type and id. In Relationship#id_hash_from_record it was hardcoded to get the id by calling record.id, which overrides the id_method_name options passed into the relationship.
I tried fixing this by only changing the code in Relationship to dynamically call the id_method_name on the object, but unfortunately on has_many relationships the default value for id_method_name would be passed as if the ids would be pulled in a batch (for example groupee_ids). That default works for regular has_manys where we get the ids all at once but fails for polymorphic ones where it loops over each object.
So, fixing the problem required passing the polymorphic information to compute_id_method_name, which now defaults to id rather than id_method_name_from_relationship in the case where the relationship is polymorphic.
This also fixes a bug where the record_id is not carried over through inheritance.