-
Notifications
You must be signed in to change notification settings - Fork 182
feat: Add the ability to override getter for JsonApiClient::Resource id #378
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
Conversation
… to have a modified id method that returns the id as an integer. This gives the application code the flexibility to match against attributes of other resources that are integers.
while this is strictly speaking against the spec, i think the change is reasonable. |
Tests seems to pass:
|
Oh I see, the method name in one of the test was incorrectly prefixed without |
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.
Looks great! thanks for contributing!
Please merge in main to get tests running in the PR
Thanks!
would you like me to fix those tests for different ruby versions? i think its got to do with Fixnum vs Integer |
|
1.21.1 is now live. Thanks for your work and patience! |
Hello, I just want to ask and see if we can modify a single line in one file
included_data.rb
. I ran into an issue needing to add a method id that will normalize the raw ids into integers, in cases of belongs_to, relationships. Please see test file here.Desired Functionality:
I want to be able create a base class that overrides the id method of a resource and consistently return it as an integer. Because I want to be able to transform back, the original type of my resource id.
This happens when we serialize active record / application record objects from mysql through json-apiserializer gem.
Their representation of id's turn into strings, that's how the json api documentation declares it so.
There seems to be only a one-liner change so that we can override the id method of a JsonApiClient::Resource
This adds the ability to create a subclass of JsonApiClient::Resource to have a modified id method that returns the id as an integer. This gives the application code the flexibility to match against attributes (ids of type integer) of other resources that are integers, which weren't translated to strings, (from gems such as json-apiserializer).