JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Filtering with .where method: no matches without ActiveRecord
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Ruby
- Estrellas
- 2.3k
- Forks
- 546
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
El punto de entrada reportado es apply_filter(records, filter, value), que actualmente llama a records.where(filter => value); empieza por ahí y compara el comportamiento de ActiveRecord y Mongoid descrito en el issue. Confirma el comportamiento previsto independiente del adaptador y añade cobertura para filtros cuyos valores sean arrays, preservando el matching existente de ActiveRecord.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- mongodb, rails, ruby
- Área
- api, backend, database
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 30/100