Surprised this is working with SQLite and you don't have to do:

    where("#{Katello::ContentViewVersionEnvironment.table_name}.environment_id" => env.id)