How to filter by polymorphic resource association filter?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia con la dichiarazione dell’associazione polimorfica documentable di DocumentsDocumentableResource e con i due esempi di richieste di filtro. Traccia il modo in cui JSONAPI Resources convalida i filtri per le relazioni polimorfiche e determina se è supportato il dispatch specifico per tipo. Il lavoro è considerato completato quando esiste un modo documentato e testato per invocare il filtro appropriato, oppure una spiegazione chiaramente circoscritta della limitazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- Ruby
- Stelle
- 2.3k
- Fork
- 546
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JSONAPI-Resources/jsonapi-resources
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
ArgumentError with Rails 8.1 Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 commenti · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
Tutte le issue di JSONAPI-Resources/jsonapi-resources
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
simp/pupmod-simp-simp#395 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
simp/pupmod-simp-rsyslog#219 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
simp/pupmod-simp-pupmod#256 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
simp/pupmod-simp-sudo#150 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100