happiness (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) (^_^) happiness

WIP ActiveRecordでAND条件をORしたいときの方法

とりあえずやってみた

posted_ats_and_user_ids = [[today, 1], [tomorrow,  2]]
conditions = Array.new(posted_ats_and_ids.size) { "id = ? AND posted_at > ?" }.join(" OR ")
# => "id = ? AND posted_at > ? OR id = ? AND posted_at > ?"

Post.where(conditions, created_ats_and_user_ids.flatten)
# => select * from posts where id = ? AND posted_at > ? OR id = ? AND posted_at > ?;

TODO

微妙に読みにくいので、模索