I have an Activities model, and they belong_to a Location
How do i select all the activities whose location.country = Australia? (for example)
Can I do this within a scope?
With the latest rails versions you can do:
Activity.joins(:location).where(locations: { country: "Australia" })
Beware:
joins(:location)
because it references the belongs_to
relationship namewhere(…)
because it references the table nameThe latter means that if you had the following:
belongs_to :location, class_name: "PublicLocation"
the query would be:
Activity.joins(:location).where(public_locations: { country: "Australia" })