Query records through its belongs_to relation in Rails
问题 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? 回答1: The kind of query you're talking about is a join. You can try queries like this in the console like: Activity.joins(:locations).where('locations.country = "Australia"') This means that SQL is going to take all the activities and locations associated with then, find the locations where country=Australia, and then