You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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:
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:
The text was updated successfully, but these errors were encountered: