Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin filters by child model

I have Order model which belongs to User model.

I need to create filter in orders by user email.

How can I do it?

like image 401
manzhikov Avatar asked Sep 11 '12 08:09

manzhikov


1 Answers

If you're looking at orders in orders.rb, and want to limit orders by the associated user then you can do:

filter :user_first_name, :as => :string

which will give you a free text search based on the Order.User.first_name relationship.

The same is true in reverse as long as the has_one and belongs_to relationships are configured correctly:

filter :order_created_at, :as => :string

Hope this is of some help.

like image 63
Andy Copley Avatar answered Nov 05 '22 10:11

Andy Copley