Skip to content

Instantly share code, notes, and snippets.

@francois-blanchard
Created September 23, 2014 09:22
Show Gist options
  • Select an option

  • Save francois-blanchard/83a24fa97fe2065eef0a to your computer and use it in GitHub Desktop.

Select an option

Save francois-blanchard/83a24fa97fe2065eef0a to your computer and use it in GitHub Desktop.
Combine two ActiveRecord objects

Combine two ActiveRecord objects

scope1 = Model.relations1.where(:color => 'blue')
scope2 = Model.relations2.where(:color => 'red')

combine_ids = (scope1 + scope2).uniq
result = Model.where(id: combine_ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment