0

How do I merge these two ActiveRecord Relations?

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')

When I do this, if one is empty they default to the empty one

@activity = activity1.merge(activity2)
teddybear
  • 546
  • 2
  • 6
  • 14
  • You mean chaining the `where` queries? – Pavan Oct 23 '15 at 16:54
  • Possible duplicate of [Combine two ActiveRecord::Relation objects](http://stackoverflow.com/questions/9540801/combine-two-activerecordrelation-objects) – Drenmi Oct 23 '15 at 17:46

1 Answers1

2

It's simple why the merge is return empty array it's because it use AND between the queries try this:

@activity = (activity1 + activity2)
matanco
  • 2,096
  • 1
  • 13
  • 20