railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.9k stars 2.26k forks source link

Searching associated: enum field #1080

Open killthekitten opened 12 years ago

killthekitten commented 12 years ago

Imagine, that we have got Model with enum field :state and AssociatedModel. When we are trying to attach AssociatedModel to Model from rails_admin interface, the search query fails: it tries to match string and integer.

This bug hides in lib/rails_admin/adapters/active_record.rb within build_statement method:

when :enum
  return if value.blank?
  ["(#{column} IN (?))", Array.wrap(value)]
end

This piece of code generates something like ...state IN ('Search string') It must return from method in case if value.blank? || value.is_a?(String) or something like that.

killthekitten commented 12 years ago

Nobody experienced this issue?

mshibuya commented 12 years ago

This problem still exists, and I've been trying to find a way to work this out...

killthekitten commented 12 years ago

I can't reproduce this issue sine I closed it (I think it was 0.0.2 or 0.0.3). Can you describe your case in more details?

neilang commented 11 years ago

This might be related to my pull request #1630

gpwest90 commented 10 years ago

I believe this still exists. Fintan explains the issues he is having here: https://groups.google.com/forum/#!msg/rails_admin/DZi4stvJyrM/zQOC9InjkisJ

I also have run into this. User roles are stored in my database as an integer, so I was using an enum to make editing a user more understandable:

def role_enum [['user',0], ['moderator',1], ['staff',2], ['admin',3]] end

However, having this in the code produces the error: invalid input syntax for integer: "string" ...ile_image_url) ILIKE '%string%') OR (users.role IN ('string')) ...

The only solution I've found so far is to remove the role_enum method.

kmanzana commented 9 years ago

We are also experiencing the same issues for a role enum method and being able to search. Any updates? Is this still a bug?

cc @raghugjoshi

simonfranzen commented 6 years ago

Thats crazy. It did not work for me and I came to a thread where they say: "Add a method enum_role and this fixes your problem". Now I am here and I have to remove my method again. A bit confusing, but in the end it worked. Edit: noooooope, I am still getting this error.

Can someone explain what goes wrong?

simonfranzen commented 6 years ago

We are still having problems getting the search work with enums...

hamdi777 commented 5 years ago

field :your_enum, :enum do enum do [ %w(first_option 0), %w(second_option 1), %w(third_option 2) ] end end

this will fix the issue with filtering your enums and it will search by the integer key but problem persists in blank and present