0

如何合并这两个 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)
4

1 回答 1

2

为什么合并返回空数组很简单,因为它AND在查询之间使用试试这个:

@activity = (activity1 + activity2)
于 2015-10-23T17:27:54.720 回答