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

Boolean fields configured as "enum" should not be searchable by default #1754

Closed
jerefrer opened this issue Sep 20, 2013 · 1 comment
Closed

Comments

@jerefrer
Copy link

Hi there,

I've just spent 4 hours chasing the why in "why the heck is this belongs_to dropdown list returning ALL users instead of just the ones matching the query ?".

I then step by step realized that this may have to do with the "searchable" state of fields. And if I may say it was insanely difficult to find out. I've searched for "autocomplete", "query", "belongs_to association" and more without ever crossing this notion of searchable state. So maybe this should be better documented. Anyway I eventually found it so here's the actual purpose of this issue:

Then I delved into rails_admin source code along with pry breakpoints to discover that many of my User model's fields were searchable, including a boolean field configured as enum.

This is where it breaks. The query conditions looked like this:

["(LOWER(users.username) LIKE ?)",
 ...,
 "users.my_boolean_field IN (?)"]

along with values ["%query%", ..., ["%query%"]]

See that users.my_boolean_field IN (?), ["%query%"] ?

Well actually this is equivalent to users.my_boolean_field IS FALSE which in my case represents almost all of the users.

I think you see my point now : enum'ed boolean fields should not be searchable unless explicitly configured to be.

Thanks for reading my story, I can go eat now.

For the record I solved the issue by explicitly telling the enum'ed boolean_field not to be searchable:

config.model User do
  list do
    field :username
    field :boolean_field, :enum do
      enum do
        [['Lie', false], ['Truth', true]]
      end
      searchable false
    end
end
@mshibuya
Copy link
Member

mshibuya commented Jun 9, 2019

Dup of #1080.

@mshibuya mshibuya closed this as completed Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants