Ruby on rails 在Rails中获取相关记录

Ruby on rails 在Rails中获取相关记录,ruby-on-rails,Ruby On Rails,这个应该很简单 我有@restaurants,它包含从餐馆模型中选择的一些记录。每个餐厅都有一个或多个位置。我想在一个实例变量中存储与@restaurants中所有餐厅对应的所有位置 这不起作用: @locations = @restaurants.locations 我该怎么办 @locations = Location.where(restaurant_id: @restaurants).all

这个应该很简单

我有@restaurants,它包含从餐馆模型中选择的一些记录。每个餐厅都有一个或多个位置。我想在一个实例变量中存储与@restaurants中所有餐厅对应的所有位置

这不起作用:

@locations = @restaurants.locations
我该怎么办

@locations = Location.where(restaurant_id: @restaurants).all