Sha256: 15ca13b75e54c936025f4ce112073c02b3da451ad5d8b903504801a658f629f3

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'rails_compatibility'
require 'rails_compatibility/active_record'

class << RailsCompatibility
  if GTE_RAILS_6_0
    def construct_join_dependency(reflect, relation)
      joins = inverse_association_joins(reflect)
      return relation.construct_join_dependency(joins, Arel::Nodes::InnerJoin)
    end
  elsif GTE_RAILS_5_2
    def construct_join_dependency(reflect, relation)
      joins = inverse_association_joins(reflect)

      join_dependency = ActiveRecord::Associations::JoinDependency.new(reflect.klass, relation.table, joins)

      root = join_dependency.send(:join_root)

      join_dependency.instance_variable_set(:@alias_tracker, relation.alias_tracker)
      join_dependency.send(:construct_tables!, root)
      return join_dependency
    end
  else
    def construct_join_dependency(reflect, _relation)
      joins = inverse_association_joins(reflect)
      return ActiveRecord::Associations::JoinDependency.new(reflect.klass, joins, [])
    end
  end

  private

  def inverse_association_joins(reflect)
    [reflect.options[:inverse_of] || reflect.active_record.table_name]
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails_compatibility-0.0.10 lib/rails_compatibility/construct_join_dependency.rb
rails_compatibility-0.0.9 lib/rails_compatibility/construct_join_dependency.rb
rails_compatibility-0.0.8 lib/rails_compatibility/construct_join_dependency.rb
rails_compatibility-0.0.7 lib/rails_compatibility/construct_join_dependency.rb
rails_compatibility-0.0.6 lib/rails_compatibility/construct_join_dependency.rb
rails_compatibility-0.0.4 lib/rails_compatibility/construct_join_dependency.rb