Reputation: 110940
I have the following:
time_range = (1.month.ago.beginning_of_month..1.month.ago.end_of_month)
Comment.where(:created_at => time_range).count
How can I add to the where clause with a statement like:
.where("user_id is not in (?)",[user_ids]).
How can I combine the two? Thanks
Upvotes: 43
Views: 69547
Reputation: 21549
Just write it like raw SQL:
Comment.where(
"(user_id > ? AND user_id < ? ) OR (created_at > ? AND created_at < ?)",
100, 200, "2022-06-01", "2022-06-05")
Comment.
where(:created_at => time_range).
where("user_id is not in (?)",[user_ids])
which will produce SQL like : select ... where ... AND ...
Upvotes: 88
Reputation: 231
User.where(["name = ? and email = ?", "Joe", "[email protected]"])
This will be fine.
Upvotes: 23