How to filter by polymorphic resource association filter?
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
調査の方向性
DocumentsDocumentableResource の polymorphic documentable association の宣言と、2 つの filter request の例から始めます。JSONAPI Resources が polymorphic relationship のフィルターをどのように検証するかを追跡し、type-specific dispatch がサポートされているかを判断します。完了条件は、適切な filter を呼び出す、文書化およびテスト済みの方法、または制限についての明確に範囲を定めた説明です。
索引モデルが issue の本文から書いたものです。
説明
This issue is a (choose one):
- Problem/bug report.
Checklist before submitting:
- I've searched for an existing issue.
Description
Bug reports:
If for example I have such setup, I have Document model that have many DocumentsDocumentables, which have documentable as polymorphic association and can have either Employee or Comment in it. I set up :
class Document < ApplicationRecord
has_many :documents_documentables, dependent: :destroy
end
class DocumentsDocumentable < ApplicationRecord
belongs_to :document
belongs_to :documentable, polymorphic: true
end
class Employee < ApplicationRecord
has_many :documents_documentables, as: :documentable
end
class Comment < ApplicationRecord
has_many :documents_documentables, as: :documentable
end
module Api
module V1
class DocumentResource < BaseResource
attributes :file_name
has_many :documents_documentables
filter :id
end
end
end
module Api
module V1
class DocumentsDocumentableResource < BaseResource
attributes :documentable_id, :documentable_type, :document_id
has_one :document
has_one :documentable, polymorphic: true, eager_load_on_include: false
end
end
end
module Api
module V1
class EmployeeResource < BaseResource
filter :custom_employee_filter, apply: lambda { |records, value, _options|
puts "custom employee filter"
}
end
end
end
module Api
module V1
class CommentResource < BaseResource
filter :custom_comment_filter, apply: lambda { |records, value, _options|
puts "custom comment filter"
}
end
end
end
Having this setup, how can I filter DocumentDocumentable by documentable.custom_<employee | comment>_filter then?
I tried smth like that:
/api/v1/documents-documentables?filter=documentable.customEmployeeFilter=filterValue , or
/api/v1/documents-documentables?filter=documentable.customCommentFilter=filterValue
Both gives me error:
{
error: {
code: "102",
detail: "documentable.customEmployeeFilter is not allowed.",
status: "400",
title: "Filter not allowed"
}
}
Is it possible at all somehow to call both filters, and if yes - how should I change my resources, is there any param I can pass to further specialize polymorpthic resource's type?
- 主要言語
- Ruby
- スター
- 2.3k
- フォーク
- 546
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JSONAPI-Resources/jsonapi-resources のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
JSONAPI-Resources/jsonapi-resources#1488 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
JSONAPI-Resources/jsonapi-resources#1479 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
JSONAPI-Resources/jsonapi-resources#1477 · コメント 3 件 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
JSONAPI-Resources/jsonapi-resources の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
riscv/riscv-unified-db#2626 ·
-
Component: GLib
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
ds-drift
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
we-promise/sure#3693 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
simp/pupmod-simp-simp#395 ·