.present?
isn't a standard method on an ActiveRecord::Relation
which is what where
returns. Calling .present?
is fetching all of the features with the given name, changing into an array and then calling .present?
on the array.
If you call .exists?
instead then the database query that is performed is slightly more optimised to checking whether that feature exists or not.
However, I'm not sure you'll notice much of a performance differences between the two options. The most likely cause is that you're missing a database index. Assuming that your association is Product has_many :features
the database query that will get generated would be improved by an index on both features.product_id
and features.name
.