Using rails_admin 0.6.2, I've added a custom field for a count of associated objects. For example, in a list of blog posts, show how many comments each has.
config.model Post do
list do
field :id
field :comment_count, :integer do
def value
bindings[:object].comment.count
end
filterable true
end
I want to be able to filter based on this number - show me posts with 0 comments, between 1 and 10, etc.
Right now there's no way it could do that, as this count is just created with an N+1 query; every time it lists a post, it queries for the comment count. I would need it to add a WHERE
condition to its earlier query for the posts.