Alexander Shlenchack
Alexander Shlenchack

Reputation: 3869

Rails, select by nested items

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

How find all clients by comment date '2012-01-30'?

Upvotes: 0

Views: 85

Answers (1)

jvnill
jvnill

Reputation: 29599

assuming date is a date type field

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

Upvotes: 2

Related Questions