rails_admin: has_many :through associations filter problem
Hi ,I have a problem with adding has many through association to filter . When I try to add this code :
list do
field :model ,:has_many_association do
searchable :name
end
end'
and then I add choose filter on the view I give the exception :
Unknown column ‘model.name’ in ‘where clause’: SELECT another_model
.* FROM another_model
WHERE (((model.name_en LIKE ‘%test%’)))
The same problem I found on the StackOVerflow but it has no answer 😦 http://stackoverflow.com/questions/13529634/rails-admin-searchable-association. Could you help me to resolve it?
About this issue
- Original URL
- State: closed
- Created 12 years ago
- Comments: 27 (10 by maintainers)
Commits related to this issue
- Implement Issue #1434 Has many association filter and tests with it , some test refactor with rspec best practices and factory girl too — committed to barsukov/rails_admin by barsukov 12 years ago
@vergenzt Thanks for your solution, it helped me a lot!!! But it introduced for me an error on all other queries.
Finally I found that the problem was in the build method of your patch.
This method returns nil if includes is empty without calling the super method and that fires the no method exception, when pagination is invoked on the result, e.g. in https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/adapters/active_record.rb :36
scope = scope.send(Kaminari.config.page_method_name, options[:page]).per(options[:per])
I think the correct solution should be this
So, the complete working patch is now: