JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Related resources not backed by an association
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 546
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Hello, I'm curious to see if anyone is interested in allowing a resource to have a relationship that isn't necessarily an association to the underlying model. For example:
A Video has_many :tags. I've created an instance method (Video#related_videos) that pulls related videos based on a video's set of tags.
video.related_videos
=> [related_video_1, related_video_2]
What I'm interested in is having the corresponding VideoResource aware that this isn't an association it should be looking for, but rather public method. This would allow the following requests:
videos/:id?include=related_videos
videos/:id/relationships/related_videos
Currently, an InvalidInclude exception will be raised since "related_videos is not a valid relationship of videos." What if we were to pass a flag to relationship / has_many / has_one? Maybe there's a better way, but I was thinking something like:
VideoResource < JSONAPI::Resource
has_many :related_videos, instance_method: true
end
Would something like this be worth exploring? I'd be happy to work on a PR to support something like this if there's any interest.
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 Prüfung der im Issue beschriebenen Deklarationen von Ressourcenbeziehungen (relationship, has_many und has_one) und des InvalidInclude-Pfads. Ermittle, wie eine öffentliche Methode wie Video#related_videos durch die beiden Beispielanfragen dargestellt und verfügbar gemacht werden könnte; die Abschlusskriterien erfordern eine Einigung über die API und das Validierungsverhalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rails, ruby
- Bereich
- api, backend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100