JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Relationships on subclasses don't adhere to model name

オープン
#823 コメント 6 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Ruby
スター
2.3k
フォーク
546
PR マージ指標
30日以内にマージされた PR はありません

説明

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)>'
...

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue に記載された namespace 付き継承のケースを、lib/jsonapi/resource.rb の _model_class、_add_relationship、inherited 付近から再現し、app/resources/api/v2/packages/meeting_package_resource.rb および app/models/packages/meeting_package.rb と比較する。完了条件は、報告された LoadError なしで resource が読み込まれ、継承された venues relationship が有効なままであり、そのケースを対象とする regression test があること。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rails, ruby
領域
api, backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。