How to filter by polymorphic resource association filter?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu với khai báo liên kết documentable đa hình của DocumentsDocumentableResource và hai ví dụ về yêu cầu bộ lọc. Truy vết cách JSONAPI Resources xác thực các bộ lọc cho các quan hệ đa hình và xác định xem việc dispatch theo từng type có được hỗ trợ hay không. Được xem là hoàn thành khi có một cách được lập tài liệu và kiểm thử để gọi bộ lọc phù hợp, hoặc một giải thích có phạm vi rõ ràng về hạn chế này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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?
- Ngôn ngữ chính
- Ruby
- Star
- 2.3k
- Fork
- 546
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JSONAPI-Resources/jsonapi-resources
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
ArgumentError with Rails 8.1 Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 bình luận · 1 reaction ·
-
Fields filtering with include Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Tất cả issue của JSONAPI-Resources/jsonapi-resources
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
simp/pupmod-simp-simp#395 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
simp/pupmod-simp-rsyslog#219 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
simp/pupmod-simp-pupmod#256 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
simp/pupmod-simp-sudo#150 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100