replace distinct by subquery, use contains_eager