JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Filtering with .where method: no matches without ActiveRecord

Aperta
#118 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Type: Maintenance
Lingua principale
Ruby
Stelle
2.3k
Fork
546
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I am really excited about the progress of JSON API spec and the JSON API Resources Gem.

In my experiments with the gem, I found the following to be incompatible with Mongoid, the ActiveRecord replacement for integrating with MongoDB.

def apply_filter(records, filter, value)
  records.where(filter => value)
end

The value passed to this method is always an array. In ActiveRecord, passing an array value to the where method builds an IN SQL query. The challenge with something like Mongoid is that values can be stored as arrays. Thus, Contact.where(:github => ['realityendshere']) seems to search for contact records where the github property is exactly equal to the array ['realityendshere'] and does not return the expected results.

It's easy to override this method in my app's resources:

def self.apply_filter(records, filter, value)
  records.in(filter => value)
end

Hopefully, this helps anyone else trying to understand how jsonapi-resources gem works with ActiveRecord alternatives.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Il punto di ingresso segnalato è apply_filter(records, filter, value), che attualmente chiama records.where(filter => value); inizia da lì e confronta il comportamento di ActiveRecord e Mongoid descritto nell’issue. Conferma il comportamento previsto indipendente dall’adapter e aggiungi coverage per i filtri con valori array, preservando il matching esistente di ActiveRecord.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
mongodb, rails, ruby
Ambito
api, backend, database
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.