I have a model setup like this:
Sale
belongs toProduct
Product
belongs toVarietal
Now I want to make a select drop down filter for varietal on sales. The only way I've managed to do this is by name.
filter :product_varietal_name,
as: :select,
label: 'Varietal name',
collection: Varietal.names_for_select
But I want to be able to serach by varietal_id
since I have an index on that column, it should be much faster. I seem to be unable to do so, however.
filter :product_varietal # undefined method `product_varietal_eq'
filter :product_varietal_id # undefined method `product_varietal_eq'
filter :product_varietal_id_eq # undefined method `product_varietal_id_eq_eq'
filter :product_varietal_eq # undefined method `product_varietal_eq_eq'
There is clearly some magic here around the _id
at the end of the filter name. And this magic is not doing what I want.
The only case this does work is when the association is on the Model being viewed. So Sale
belongs to Product
, and filter :product
works as you would expect.
So how can I make a drop down select box filter that searches on sale.product.varietal_id
?