JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Namespaced resources don't infer namespaced model_name

Open
#1,152 0 comments 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 don't know if this is by design or a bug, but given the follwing model and resource, the resource cannot infer the model name because of demodulize in https://github.com/cerebris/jsonapi-resources/blob/5af1f17068b66b0a17b7b69e5db334c640f6f34b/lib/jsonapi/resource.rb#L925

# model
module Foo
  class Bar < ApplicationRecord
  end
end

# resource
module Foo
  class BarResource < JSONAPI::Resource
    # model_name Foo::Bar' <= with this, things work fine, without, you'll get a warn "[MODEL NOT FOUND] warning
  end
end

If the resource is defined inside a module, should't we prefix the model_name with the same module by default to permit model_name inferring ?

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 at lib/jsonapi/resource.rb around line 925 and reproduce the Foo::Bar and Foo::BarResource example from the issue. The work is done when a resource defined inside a module infers the matching namespaced model without an explicit model_name and no MODEL NOT FOUND warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.