In activerecord, preferably without literal sql, I’m trying to get roughly this going:
Thing.where(:id => Link.select(:col1).where(subquery1), :id => Link.select(:col2).where(subquery2))
I need it to give me an AND between the subqueries, but instead the last subquery overrides the preceding ones.
Note: I’m selecting a different column from the Link table in each subquery
I’ve already tried this:
t = Thing.where(:id => Link.where(subquery1))
t.where(:id => Link.where(subquery2))
Also note the nature of the subqueries mean I can’t put my AND into a single subquery
Any way to do this in ActiveRecord without resorting to SQL?
I’m using Rails 3 and PostgreSQL
Thanks!
You are probably better off chaining two where conditions then combining them.
This will add the
ANDbetween the twoINqueries.