class Ransack::Adapters::ActiveRecord::Context

def build_association(name, parent = @base, klass = nil)

def build_association(name, parent = @base, klass = nil)
  if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
    jd = Polyamorous::JoinDependency.new(
      parent.base_klass,
      parent.table,
      Polyamorous::Join.new(name, @join_type, klass),
      @join_type
    )
    found_association = jd.instance_variable_get(:@join_root).children.last
  else
    jd = Polyamorous::JoinDependency.new(
      parent.base_klass,
      parent.table,
      Polyamorous::Join.new(name, @join_type, klass)
    )
    found_association = jd.instance_variable_get(:@join_root).children.last
  end
  @associations_pot[found_association] = parent
  # TODO maybe we dont need to push associations here, we could loop
  # through the @associations_pot instead
  @join_dependency.instance_variable_get(:@join_root).children.push found_association
  # Builds the arel nodes properly for this association
  if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
    @tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
  else
    @join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
  end
  # Leverage the stashed association functionality in AR
  @object = @object.joins(jd)
  found_association
end