JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Relationships on subclasses don't adhere to model name
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
A LoadError is thrown when trying to load a resource model with a namespaced custom model name that inherits from a abstract resource model that declares a relation.
Verified in versions 0.8.0.beta2 and 0.7.0
Modules:
module API
module V2
module Packages
class PackageResource < BaseResource
abstract
has_many :venues
end
end
end
end
module API
module V2
module Packages
class MeetingPackageResource < PackageResource
model_name 'Packages::MeetingPackage'
has_many :services, class_name: 'MeetingPackageService'
end
end
end
end
Path to meeting package module:
app/models/packages/meeting_package.rb
Error stack trace:
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:495:in `load_missing_constant': Unable to autoload constant MeetingPackage, expected /app/models/packages/meeting_package.rb to define it (LoadError)
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:184:in `const_missing'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:261:in `const_get'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:261:in `block in constantize'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `each'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `inject'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `constantize'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:304:in `safe_constantize'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/string/inflections.rb:77:in `safe_constantiz
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.8.0.beta2/lib/jsonapi/resource.rb:934:in `_model_class'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.8.0.beta2/lib/jsonapi/resource.rb:974:in `block in _add_relationship'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.8.0.beta2/lib/jsonapi/resource.rb:970:in `each'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.8.0.beta2/lib/jsonapi/resource.rb:970:in `_add_relationship'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.8.0.beta2/lib/jsonapi/resource.rb:411:in `block in inherited'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.8.0.beta2/lib/jsonapi/resource.rb:408:in `each_value'
/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/jsonapi-resources-0.8.0.beta2/lib/jsonapi/resource.rb:408:in `inherited'
/app/resources/api/v2/packages/meeting_package_resource.rb:4:in `<module:Packages>'
/app/resources/api/v2/packages/meeting_package_resource.rb:3:in `<module:V2>'
/app/resources/api/v2/packages/meeting_package_resource.rb:2:in `<module:API>'
/app/resources/api/v2/packages/meeting_package_resource.rb:1:in `<top (required)>'
...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the namespaced inheritance case from the issue, starting at lib/jsonapi/resource.rb around _model_class, _add_relationship, and inherited; compare it with app/resources/api/v2/packages/meeting_package_resource.rb and app/models/packages/meeting_package.rb. Done means the resource loads without the reported LoadError and the inherited venues relationship remains valid, with a regression test covering the case.
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
- 42/100