If I have a model Person
, which has_many
Vehicles
and each Vehicle
can be of type car
or motorcycle
, how can I query for all persons, who have cars and all persons, who have motorcycles?
I don't think these are correct:
Person.joins(:vehicles).where(vehicle_type: 'auto')
Person.joins(:vehicles).where(vehicle_type: 'motorcycle')
includes/joins
methods use the name defined in the model", but in the second example you writePost.includes(:user)
. Don't you mean that pluralization inincludes/joins
depends on the relationship of the two models? – Xanthene