I would use sql query here
```ruby
def products(env)
  Product.joins(:repositories => :environment).where(:environment => {:id => env}).uniq
end
```