Class: BabySqueel::JoinDependency::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/baby_squeel/join_dependency.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation) ⇒ Builder

Returns a new instance of Builder.



61
62
63
# File 'lib/baby_squeel/join_dependency.rb', line 61

def initialize(relation)
  @join_dependency = build(relation, collect_joins(relation))
end

Instance Attribute Details

#join_dependencyObject (readonly)

Returns the value of attribute join_dependency.



59
60
61
# File 'lib/baby_squeel/join_dependency.rb', line 59

def join_dependency
  @join_dependency
end

Instance Method Details

#find_alias(associations) ⇒ Object

Find the alias of a BabySqueel::Association, by passing a list (in order of chaining) of associations and finding the respective JoinAssociation at each level.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/baby_squeel/join_dependency.rb', line 68

def find_alias(associations)
  if BabySqueel::ActiveRecord::VersionHelper.at_least_6_1?
    # construct_tables! got removed by rails
    # https://github.com/rails/rails/commit/590b045ee2c0906ff162e6658a184afb201865d7
    #
    # construct_tables_for_association! is a method from the polyamorous (ransack) gem
    join_root = join_dependency.send(:join_root)
    join_root.each_children do |parent, child|
      join_dependency.construct_tables_for_association!(parent, child)
    end
  elsif BabySqueel::ActiveRecord::VersionHelper.at_least_5_2_3?
    # If we tell join_dependency to construct its tables, Active Record
    # handles building the correct aliases and attaching them to its
    # JoinDepenencies.
    join_dependency.send(:construct_tables!, join_dependency.send(:join_root))
  end

  join_association = find_join_association(associations)
  join_association.table
end