class Ransack::Adapters::ActiveRecord::JoinAssociation

def build_constraint(reflection, table, key, foreign_table, foreign_key)

def build_constraint(reflection, table, key, foreign_table, foreign_key)
  if reflection.options[:polymorphic]
    super.and(
      foreign_table[reflection.foreign_type].eq(reflection.klass.name)
    )
  else
    super
  end
end