Ransack: _in predicate does not work for array attribute

Created on 18 Mar 2018  路  2Comments  路  Source: activerecord-hackery/ransack

I have a Rails model call InfoData and it has an attribute called error_codes. The codes are stored in an array like so [9,7,10,21] (integer[]) .

InfoData.first.error_codes 
=> [9,7,5]

I try to use ransack on it in order to search if a specific code is present(via a select option). For error_codes_in (_in ransack predicate) I receive the following error

operator does not exist: integer[] = integer
LINE 1: ...ranch_id" WHERE "info_data"."error_codes" IN (9) A...
                                                         ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

Is there a way around this?

Help Wanted

Most helpful comment

Ransack can search Postgres arrays using a custom predicate, this solution looks pretty good, and could be added to the Ransack core. Related

All 2 comments

Ransack can search Postgres arrays using a custom predicate, this solution looks pretty good, and could be added to the Ransack core. Related

Is there a community member willing to implement a new predicate as described above?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timoschilling picture timoschilling  路  5Comments

maduhaime picture maduhaime  路  5Comments

itsalongstory picture itsalongstory  路  3Comments

zenati picture zenati  路  4Comments

MatsumotoHiroko picture MatsumotoHiroko  路  4Comments