JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

JR not including type of polymorphic has_one when called to include it

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

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

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

説明

The response from the server is missing the embedded target/data/type, or rather replacing it with the empty string...

class Api::V1::ActivityResource < JSONAPI::Resource
  has_one :user
  has_one :target, polymorphic: true
  attributes :previous_value, :new_value, :message, :created_at
  attribute :activity_type   # this is included for now as JSONAPI::Resources sends model type as "activities"
  def activity_type
    @model.type
  end
end
irb(main):001:0> Activity.first
  Activity Load (0.7ms)  SELECT  "activities".* FROM "activities"  ORDER BY "activities"."id" ASC LIMIT 1
=> #<NewRecord id: 1, 
          user_id: nil, 
        target_id: 239, 
      target_type: "Facility",   # <= target_type is correct
   previous_value: nil, 
        new_value: nil, 
          message: nil, 
             type: "NewRecord", 
       created_at: "2015-10-13 15:16:12", 
       updated_at: "2015-10-13 15:16:12">

http://localhost:3000/api/v1/activities/1?include=target,user:

{
    "data": {
        "id": "1",
        "type": "activities",
        "links": {
            "self": "http://localhost:3000/api/v1/activities/1"
        },
        "attributes": {
            "previous-value": null,
            "new-value": null,
            "message": null,
            "created-at": "2015-10-13T15:16:12.964Z",
            "type": "NewRecord"
        },
        "relationships": {
            "user": {
                "links": {
                    "self": "http://localhost:3000/api/v1/activities/1/relationships/user",
                    "related": "http://localhost:3000/api/v1/activities/1/user"
                },
                "data": null
            },
            "target": {
                "links": {
                    "self": "http://localhost:3000/api/v1/activities/1/relationships/target",
                    "related": "http://localhost:3000/api/v1/activities/1/target"
                },
                "data": {
                    "type": "",    // <== should be "Facility"
                    "id": "239"
                }
            }
        }
    }
}

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

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

はじめの一歩

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

調査の方向性

示されている ActivityResource リクエストを include=target,user で再現し、多相的な has_one :target リレーションがどのようにリソース識別子を構築するかを調査します。含まれるリレーションデータが、空のタイプではなくタイプ Facility と id 239 を報告することを確認して、修正を検証します。

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

評価

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

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

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