2013-03-09 110 views
0
class Client < ActiveRecord::Base 
attr_accessible :name 
has_many :comments, :dependent => :destroy 
end 

class Comment < ActiveRecord::Base 
attr_accessible :title, :date 
belongs_to :client 
end 

如何找到所有客戶評論日期'2012-01-30'?導軌,通過嵌套項目選擇

回答

2

假設date是日期類型字段

Client.joins(:comments).where(comments: { date: Date.new(2012,1,30) })