我有以下型號:如何檢索特定時期內深度關聯的值?
Company has_many :businesses
Business belongs_to :company
Business has_many :employees
Employee belongs_to :business
Employee has_many :votes
Vote belongs_to :employee
attr_accessible :score
從公司的什麼是得到所有選票人都屬於所有屬於該公司的企業員工全部得分的最佳方式?
我會用has_many還是創建查詢或使用gem?
然後我怎麼會限制結果只顯示過去30天/ 1個月前的分數?
我已經試過:
scores = self.businesses.employees.votes.where(created_at: Date.today.1.month.ago).pluck(:score)
我也試過 公司的has_many:企業 公司的has_many:投票通過:企業
Business belongs_to :company
Business has_many :employees
Business has_many :votes, through: :employees
Employee belongs_to :business
Employee has_many :votes
Vote belongs_to :employee
attr_accessible :score
@company.votes.pluck(:score)
我使用PostgreSQL
你如何存儲票? – zogby
我存儲了一個分數。更新 – grabury