JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Error with aliased attr's into dasherized strings- Unable to update record with "no implicit conversion of nil into Hash" error

Open
#1,053 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

I am running into an issue when attempting to save records with properties that have been aliased into a dasherized string.

I have a model like this:

# models/location.rb
class Location < ApplicationRecord
  alias_attribute :numberOfColors, :number_of_colors__c
end

And my resource:

# resources/location_resource.rb:
class LocationResource < JSONAPI::Resource
  attributes :numberOfColors
end

Sending a patch request like so returns the error no implicit conversion of nil into Hash.

{  
  "data":{  
    "id":"somerecordid",
    "attributes":{  
      "colors": 3,
    },
    "type":"locations"
  }
}
  • If I skip the aliasing and pass in the attr as number-of-colors--c everything works as expected.
  • If I name the attr colors everything works as expected.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the PATCH request using models/location.rb and resources/location_resource.rb, then compare the aliased dasherized attribute with the working unaliased cases described in the issue. Trace the attribute update path until the nil-to-Hash error is identified; done means saving through the alias succeeds without the error while the existing working cases remain intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.