JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Strategy for grouped resources
Nessuno ha ancora preso questa issue.
- Lingua principale
- Ruby
- Stelle
- 2.3k
- Fork
- 546
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I realize this isn't exclusively a JR question, but I feel it's too common to not bring it up and how one might accomplish it using JR.
My current use case has a type of model that's the basis for summed queries grouped by one or more attributes. In this case, it's a timesheet entry, and I initially need to group them by user_id and project_id, but they could easily be grouped by time periods as well. The aggregated value is SUM(hours). I've created an TimesheetEntryCollection model as an ActiveModel::Model object to handle the aggregated data, but I'm unsure how to serialize them, as JR expects and ActiveRecord::Relation to be returned from the Resource's self.records method and I'm not sure how to force a relation out of a tableless model. Do I just need to override the controller methods, or is there some way to do this through the resource?
Am I thinking about this the wrong way? Should JR maybe allow arrays to be returned from self.records with the understanding that you have to handle pagination/filtering yourself?
Any help would be greatly appreciated!
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.
Direzione di ricerca
Inizia dal contratto self.records di Resource e dai metodi del controller menzionati nel report, quindi traccia il modo in cui JR serializza una ActiveRecord::Relation. Confronta questo percorso con il modello ActiveModel::Model senza tabella TimesheetEntryCollection e il caso d’uso di SUM(hours) raggruppato. Il lavoro è completato quando è stato concordato un approccio per le risorse raggruppate, incluso stabilire se sono supportati gli array e la paginazione o il filtraggio gestiti dal chiamante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rails, ruby
- Ambito
- api, backend
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100