Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_in predicate does not work for array attribute #897

Open
mirceadaniel opened this issue Mar 18, 2018 · 3 comments
Open

_in predicate does not work for array attribute #897

mirceadaniel opened this issue Mar 18, 2018 · 3 comments

Comments

@mirceadaniel
Copy link

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?

@scarroll32
Copy link
Member

scarroll32 commented Dec 18, 2018

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

@scarroll32
Copy link
Member

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

@jakemumu
Copy link

did anyone have a simpler solution for this? I'd like to match array to *_in across multiple ids, so if a has_many association contains both X_ID && Y_ID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants