Sha256: fd35fbc01a1d7de1a47d2ae2e1f82380d4e9ee39d87d1a6b02518f7d1eba60d2

Contents?: true

Size: 1.57 KB

Versions: 188

Compression:

Stored size: 1.57 KB

Contents

module ActiveRecord
  module Associations
    # Helper class module which gets mixed into JoinDependency::JoinAssociation and AssociationScope
    module JoinHelper #:nodoc:

      def join_type
        Arel::InnerJoin
      end

      private

      def construct_tables
        tables = []
        chain.each do |reflection|
          tables << alias_tracker.aliased_table_for(
            table_name_for(reflection),
            table_alias_for(reflection, reflection != self.reflection)
          )

          if reflection.source_macro == :has_and_belongs_to_many
            tables << alias_tracker.aliased_table_for(
              (reflection.source_reflection || reflection).options[:join_table],
              table_alias_for(reflection, true)
            )
          end
        end
        tables
      end

      def table_name_for(reflection)
        reflection.table_name
      end

      def table_alias_for(reflection, join = false)
        name = "#{reflection.plural_name}_#{alias_suffix}"
        name << "_join" if join
        name
      end

      def join(table, constraint)
        table.create_join(table, table.create_on(constraint), join_type)
      end

      def sanitize(conditions, table)
        conditions = conditions.map do |condition|
          condition = active_record.send(:sanitize_sql, interpolate(condition), table.table_alias || table.name)
          condition = Arel.sql(condition) unless condition.is_a?(Arel::Node)
          condition
        end

        conditions.length == 1 ? conditions.first : Arel::Nodes::And.new(conditions)
      end
    end
  end
end

Version data entries

188 entries across 157 versions & 15 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/activerecord-3.2.22.5/lib/active_record/associations/join_helper.rb
activerecord-3.2.22.5 lib/active_record/associations/join_helper.rb
activerecord-3.2.22.4 lib/active_record/associations/join_helper.rb
activerecord-3.2.22.3 lib/active_record/associations/join_helper.rb
activerecord-3.2.22.2 lib/active_record/associations/join_helper.rb
activerecord-3.2.22.1 lib/active_record/associations/join_helper.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/associations/join_helper.rb
activerecord-3.2.22 lib/active_record/associations/join_helper.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.12/lib/active_record/associations/join_helper.rb
activerecord-3.2.21 lib/active_record/associations/join_helper.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/associations/join_helper.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/associations/join_helper.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/associations/join_helper.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/associations/join_helper.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/associations/join_helper.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/associations/join_helper.rb
activerecord-3.2.20 lib/active_record/associations/join_helper.rb
activerecord-3.2.19 lib/active_record/associations/join_helper.rb
activerecord-3.2.18 lib/active_record/associations/join_helper.rb
activerecord-3.2.17 lib/active_record/associations/join_helper.rb