Skip to content

Fix: Cannot access associations of 'dashed' type for a newly initialised resource. #372

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

inderps
Copy link
Contributor

@inderps inderps commented Nov 27, 2020

If you have resource with associations of dashed types. You cannot access those associations because of the bug

# {
#   id: 1,
#   type: 'dashed-owners',
#   attributes: {
#     name: "Arjuna"
#   }
# }

class DashedOwner < Formatted
end

class DashedProperty < Formatted
  has_one :dashed_owner
end

dashed_owner = DashedOwner.find(1).first
dashed_property = DashedProperty.new(dashed_owner: dashed_owner)

Accessing below will results in following error

dashed_property.dashed_owner

NameError: uninitialized constant DashedProperty::Dashed-owner

Copy link
Collaborator

@gaorlov gaorlov left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to contribute! The change looks good. Only thing: would you mind updating the chsngelog with a description of the change?

Thanks!

@inderps
Copy link
Contributor Author

inderps commented Dec 2, 2020

@gaorlov Thanks for looking into it. Sure, I can do that

@inderps inderps deleted the fix/initializing-resources-with-associations-of-dashed-types branch December 2, 2020 11:52
@inderps inderps restored the fix/initializing-resources-with-associations-of-dashed-types branch December 2, 2020 11:53
@inderps
Copy link
Contributor Author

inderps commented Dec 2, 2020

@gaorlov

I was referring this PR in one of my private project and I closed that PR and Github also closed this magically. I reopend it now. Apologies for that

@inderps inderps reopened this Dec 2, 2020
@gaorlov gaorlov merged commit ea8fa20 into JsonApiClient:master Dec 2, 2020
@gaorlov
Copy link
Collaborator

gaorlov commented Dec 2, 2020

@inderps thanks a ton for your contribution!
json_api_client (1.18.0) is now live in rubygems.

@inderps
Copy link
Contributor Author

inderps commented Dec 3, 2020

@gaorlov Awesome 🙏 thank you very much

@inderps inderps deleted the fix/initializing-resources-with-associations-of-dashed-types branch December 3, 2020 06:25
@gaorlov
Copy link
Collaborator

gaorlov commented Dec 3, 2020

@inderps any time!
My notifications for this project don't always fire correctly, so feel free to email me directly if I don't respond to a PR within a few days.

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.

None yet

2 participants