I am running 2 (sometimes 3) searches, like:
first_search = Company.where('...') # returns 2 objects
second_search = Company.where('...') # returns 4 objects
Let's say that first_search
contains objects with these IDs:
10
20
second_search
contains
10
30
40
50
I would like to save to another variable (say results
) objects with the same IDs from first_search
and second_search
, thus results
would only contain the object with ID:
10
How to do this?
Thank you/
EDIT:
the intersection is working based on the id
column, right? Would be there a way to make the intersection work on a different column? Say name
?