@properties = Property.where(id: property_ids)
.joins(:property_values).select('"property_values"."value"').distinct.references(:property_values)
Note I changed includes
to a join as includes
loads data in a separate query where as join
actually does a join allowing you to perform action on the data within the query..
I have used the distinct method instead of putting it within the select however you could do this but you would need to remove the word select from your string
@properties = Property.where(id: property_ids)
.joins(:property_values).select('distinct "property_values"."value"').references(:property_values)
Read more http://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html