There's a couple of things to note here.
Firstly: attributes are a better fit for sorting (they're sortable by their very nature)... but yes, if you want to sort by the minimum price, then you're going to need a SQL snippet for that:
has 'MIN(prices.value)', as: :price, type: :float
You will also need to ensure you're referring to the prices
association either in a separate field or attribute, or explicitly in a call to join
, to ensure the table is actually part of the joins in the generated SQL query:
join prices
However, the error you're seeing is unrelated to this - it's complaining that it can't determine the type of an attribute because the specified column doesn't exist. I'm pretty certain this is from your price_id
attribute, which should probably go through the prices
association:
has prices.id, as: :price_ids
Making this change has the added bonus of ensuring the SQL join exists for the prices
table, and so you don't need the join prices
line in your index definition.