stas / jsonapi.rb

Lightweight, simple and maintained JSON:API support for your next Ruby HTTP API.
MIT License
262 stars 58 forks source link

Field attributes containing patched predicates are mishandled #69

Closed ghost closed 2 years ago

ghost commented 3 years ago

Hello,

Expected Behavior

Field attributes containing/ending with any of the custom predicates added by the gem should extract the correct field, and returns the filtered records.

Actual Behavior

Using field attributes that can contains or ends with _max (and all other custom predicates added by the gem: min, max, avg, sum and count) like bar_abs_max, bar_abs_min are mishandled, the gem is extracting as field bar_abs, so using filter like bar_abs_max_gteq does not work: it returns all records.

Steps to Reproduce the Problem

  1. create a model/record field containing/ending with one of the custom predicates (min, max, avg, sum and count)
  2. request with any filter and other ransack predicates
  3. check the SQL query & result

Specifications

A quick solution would be to give the developer the choice to enable or not these custom predicates

stas commented 2 years ago

@BenjaminMINK sorry for the delay replying to this one. Have you considered enabling the expressions when filtering? https://github.com/stas/jsonapi.rb#sorting-using-expressions

Feel free to reopen this if you have questions ;)