Reputation: 8730
Association of model is
class Campaign
has_many :views_logs
has_many :users, through: :views_logs
end
I want to get only those users of campaign where views_logs
is created b/w specific dates.
Note: created_at query for views_logs
not for Users creation
Upvotes: 1
Views: 189
Reputation: 1500
Campaign.joins(:users).where("views_logs.created_at = ?", my_date)
Joining Users like this will perform a SQL JOIN
on your views_logs then a SQL JOIN
on your users, which allows you to use a view_logs column in your WHERE
condition.
Upvotes: 1