[英]Getting associated records in Rails
这应该很容易。
我有@restaurants,其中包含来自Restaurant模型的选定数量的记录。 每个餐厅都有一个或多个位置。 我想在实例变量中存储与@restaurants中所有餐厅相对应的所有位置。
这不起作用:
@locations = @restaurants.locations
我该怎么办?
@locations = Location.where(restaurant_id: @restaurants).all
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.