I am using Rails 3.1.0
I have two models, A and B.
A has_one B, but B can be null.
B belongs_to A.
B has a boolean field called “visible.”
I want to get all A records that have a non-null B and a B with “visible” set to true.
What is a concise and efficient way of doing this query?
What I’ve done so far:
I created a scope that gets the A’s with non-null B’s (I think).
scope :has_b, includes(:b).where(B.arel_table[:id].not_eq(nil))
Is there a way to chain the visible == true condition to this scope?
Zach Kemp was almost right
So, in scope: