Sha256: 19e091099eb98fd977b95cf9e1cc1293f0fd261aedfce38edebf952be07461d9

Contents?: true

Size: 1.18 KB

Versions: 27

Compression:

Stored size: 1.18 KB

Contents

module ActiveRecord
  module Associations
    class JoinDependency
      class JoinPart
        def aliased_primary_key
          # CPK
          # "#{aliased_prefix}_r0"

          active_record.composite? ?
            primary_key.inject([]) {|aliased_keys, key| aliased_keys << "#{ aliased_prefix }_r#{aliased_keys.length}"} :
            "#{ aliased_prefix }_r0"
        end

        def record_id(row)
          # CPK
          # row[aliased_primary_key]
          active_record.composite? ?
            aliased_primary_key.map {|key| row[key]}.to_composite_keys :
            row[aliased_primary_key]
        end

        def column_names_with_alias
          unless @column_names_with_alias
            @column_names_with_alias = []

            # CPK
            #([primary_key] + (column_names - [primary_key])).each_with_index do |column_name, i|
            keys = active_record.composite? ? primary_key.map(&:to_s) : [primary_key]

            (keys + (column_names - keys)).each_with_index do |column_name, i|
              @column_names_with_alias << [column_name, "#{aliased_prefix}_r#{i}"]
            end
          end
          @column_names_with_alias
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
composite_primary_keys-5.0.14 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.13 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.12 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.11 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.10 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.9 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.8 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.6 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.5 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.4 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.2 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.1 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.0 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-5.0.0.rc1 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-4.1.2 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-4.1.1 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-4.0.0 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-4.0.0.beta9 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-4.0.0.beta8 lib/composite_primary_keys/associations/join_dependency/join_part.rb
composite_primary_keys-4.0.0.beta7 lib/composite_primary_keys/associations/join_dependency/join_part.rb