I am wondering if there is anyway to combine these two queries without using a string in the where call… ?
Notification.where(:notifiable_type => "Post", :notifiable_id => post.id)
Notification.where(:notifiable_type => "Comment", :notifiable_id => post.comments.map(&:id))
In other words, I am looking for a way to accomplish this without doing:
Notification.where("(notifiable_type = 'Post' AND notifiable_id = ?) OR (notifiable_type = 'Comment' AND notifiable_id in (?))", [post.id, post.comments.map(&:id)])
Is it possible?
You can use MetaWhere to achieve what you are looking for in a clean and readable way: