如何合并这两个ActiveRecord关系?
activity1 = PublicActivity::Activity.where("user_recipients LIKE ':id,%' or user_recipients LIKE '%, :id' or user_recipients LIKE '%, :id,%' or user_recipients = ':id'", id: current_user.id)
activity2 = PublicActivity::Activity.where(recipient_id: current_user.id, recipient_type: 'User')
当我这样做时,如果一个为空,则默认为空
@activity = activity1.merge(activity2)
答案 0 :(得分:2)
为什么合并返回空数组很简单,因为它在查询之间使用AND
试试这个:
@activity = (activity1 + activity2)