Rails 3 ActiveRecord where clause where id is set or null
问题 I have an ActiveRecord, Annotation, with two columns: user_id and post_id, which can be null. An annotation with null user_id and post_id are "global" annotations that are applicable to all posts across all users. I would like to retrieve all annotations associated with a particular user's post AND all global annotations. In MySQL, the SQL command would be select * from annotations where (user_id = 123 and post_id = 456) or (user_id is null and post_id is null) In Rails 3, what is best way to