module ActiveRecord::Associations::ThroughAssociation

def target_scope

2. To get the type conditions for any STI models in the chain
1. To get the default_scope conditions for any of the other reflections in the chain

We merge in these scopes for two reasons:
def target_scope
  scope = super
  reflection.chain.drop(1).each do |reflection|
    relation = reflection.klass.scope_for_association
    scope.merge!(
      relation.except(:select, :create_with, :includes, :preload, :eager_load, :joins, :left_outer_joins)
    )
  end
  scope
end