JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Automatic include directives from filtering on a relationship column?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 546
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der im Issue gezeigten Funktion apply_filters und verfolge, wie apply_includes und IncludeDirectives erforderliche Relationship-Includes behandeln. Vergleiche das resultierende Antwortverhalten mit der JSON:API-Spezifikation und ermittle und dokumentiere anschließend, ob das Filtern nach einer Relationship-Spalte nur die Top-Level-Ressource oder auch die gefilterte Relationship zurückgeben sollte.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- ruby
- Bereich
- api, backend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 30/100