Rails,由嵌套项选择

时间:2013-03-09 08:36:33

标签: ruby-on-rails select activerecord

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

如何按评论日期查找所有客户&#39; 2012-01-30&#39;?

1 个答案:

答案 0 :(得分:2)

假设date是日期类型字段

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