Module: ArelHelpers::JoinAssociation

Extended by:
ActiveSupport::Concern
Defined in:
lib/arel-helpers/join_association.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.join_association(table, association, join_type = Arel::Nodes::InnerJoin, options = {}, &block) ⇒ Object

activerecord uses JoinDependency to automagically generate inner join statements for any type of association (belongs_to, has_many, and has_and_belongs_to_many). For example, for HABTM associations, two join statements are required. This method encapsulates that functionality and yields an intermediate object for chaining. It also allows you to use an outer join instead of the default inner via the join_type arg.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/arel-helpers/join_association.rb', line 20

def join_association(table, association, join_type = Arel::Nodes::InnerJoin, options = {}, &block)
  if ActiveRecord::VERSION::STRING >= '5.0.0'
    join_association_5_0(table, association, join_type, options, &block)
  elsif ActiveRecord::VERSION::STRING >= '4.2.0'
    join_association_4_2(table, association, join_type, options, &block)
  elsif ActiveRecord::VERSION::STRING >= '4.1.0'
    join_association_4_1(table, association, join_type, options, &block)
  else
    join_association_3_1(table, association, join_type, options, &block)
  end
end