2013-03-09 109 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) })