簡體   English   中英

在Rails中獲取關聯記錄

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM