JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Automatic include directives from filtering on a relationship column?

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

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

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

説明

In the apply filters function:


    def apply_filters(records, filters, options = {})
      required_includes = []

      if filters
        filters.each do |filter, value|
          if _resource_klass._relationships.include?(filter)
            if _resource_klass._relationships[filter].belongs_to?
              records = apply_filter(records, _resource_klass._relationships[filter].foreign_key, value, options)
            else
              required_includes.push(filter.to_s)
              records = apply_filter(records, "#{_resource_klass._relationships[filter].table_name}.#{_resource_klass._relationships[filter].primary_key}", value, options)
            end
          else
            records = apply_filter(records, filter, value, options)
          end
        end
      end

      if required_includes.any?
        records = apply_includes(records, options.merge(include_directives: IncludeDirectives.new(_resource_klass, required_includes, force_eager_load: true)))
      end

      records
    end

I noticed there is a line where the filtered relationships are then added as includes which then get returned.

 if required_includes.any?
        records = apply_includes(records, options.merge(include_directives: IncludeDirectives.new(_resource_klass, required_includes, force_eager_load: true)))
      end

This means that I can never just filter on a relationship column but just return the top level object, I have to return the whole filtered relationship as well.

Is that right? Is that in accordance with the JSON API spec?

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

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

はじめの一歩

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

調査の方向性

issue に示されている apply_filters 関数から開始し、apply_includes と IncludeDirectives が必須のリレーションシップのインクルードをどのように処理するかを追跡します。結果として返されるレスポンスの挙動を JSON:API 仕様と比較し、リレーションシップ列によるフィルタリングでトップレベルリソースのみを返すべきか、それともフィルタリングされたリレーションシップも返すべきかを判断して文書化します。

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

評価

技術スタック
ruby
領域
api, backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

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

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