Scopes chaining by OR
'coalesce(rs_reputations.value, 0) &gt; ? OR purchases.force_active = true OR (? AND purchases.user_id = ?)',
LOWEST_VOTE,
!user.id.nil?,
(if user.id.nil? then -1 else user.id end)


This is semantically equivalent to both, but the AND in the third clause prevents it from having an effect when there is no user.id.