【发布时间】:2018-04-24 21:29:15
【问题描述】:
我有一个表 :periods 有一列 :hours
我还有一个表 :simulations 属于 :period (所以它有 period_id 作为列)
我加入2桌
@simulations=Simulation.join(:period) #Controller
现在在我看来,我必须遍历我的模拟,但要根据周期表中存在的“小时”列进行过滤。
所以我尝试了类似的东西
在我看来,我必须循环模拟:
<% @simulations.where( :period => {:hour => count})each do |sim| %>
或
<% @simulations.periods.where(:hour => count )each do |sim| %>
再次,我想根据周期表中的数据过滤我的模拟。这些方法都不起作用。我也尝试过使用 include 和 eager_loads,这两种方法都不起作用。
我是否正在尝试一些在 Rails 下不可能的事情?
我也在使用 postgres
【问题讨论】:
标签: ruby-on-rails postgresql join filter include