JsonApiClient / json_api_client

Build client libraries compliant with specification defined by jsonapi.org
MIT License
362 stars 186 forks source link

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

Closed inderps closed 3 years ago

inderps commented 3 years ago

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
inderps commented 3 years ago

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

inderps commented 3 years ago

@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

gaorlov commented 3 years ago

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

inderps commented 3 years ago

@gaorlov Awesome 🙏 thank you very much

gaorlov commented 3 years ago

@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.