Can't figure out how to filter nested association belongs to while search in rails admin.
I have the following code in my rails_admin config in model.
class Painting < ApplicationRecord
...
rails_admin do
configure :translations, :globalize_tabs
create do
field :author do
searchable [:last_name]
queryable [:last_name]
filterable true
end
field :genre
field :technique
field :material
field :active
field :painting_images
field :author_preview
field :translations
end
end
I tried every configuration in model. But nothing works. Whatever I enter in this dropdown input is being ignored.
I have the following logs in puma server.
Started GET "/admin/author?associated_collection=author&compact=true¤t_action=create&source_abstract_model=painting&query=George" for 127.0.0.1 at 2018-03-14 22:07:11 +0300
Processing by RailsAdmin::MainController#index as JSON
Parameters: {"associated_collection"=>"author", "compact"=>"true", "current_action"=>"create", "source_abstract_model"=>"painting", "query"=>"George", "model_name"=>"author"}
Admin Load (0.3ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Painting Load (0.3ms) SELECT "paintings".* FROM "paintings" WHERE "paintings"."id" IS NULL ORDER BY "paintings"."id" DESC LIMIT $1 [["LIMIT", 1]]
(0.3ms) SELECT COUNT(*) FROM "authors"
Author Load (0.4ms) SELECT "authors".* FROM "authors" ORDER BY authors.id desc LIMIT $1 [["LIMIT", 30]]
Author::Translation Load (0.6ms) SELECT "author_translations".* FROM "author_translations" WHERE "author_translations"."author_id" IN (114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85)
Completed 200 OK in 61ms (Views: 1.4ms | ActiveRecord: 1.9ms)
The thing is everything I enter in input is being processed in parameters but never gets evaluated. So it just ignored, it doesn't filter associated collection by params[:query]
I use globalize
gem for translations and don't know how to properly configure rails admin to use it filters.
I did searching in original repo. I think somehow is wrong this
def get_collection(model_config, scope, pagination)
...
options = options.merge(query: params[:query]) if params[:query].present?
...
model_config.abstract_model.all(options, scope)
end
This query is available here, but it's ignored there.
I tried to use
model_config.abstract_model.all(options, scope).where(last_name: params[:query])
And this is working. But this is definitely wrong. Can someone help me with more generic approach to this problem?