Sha256: 19d0deda9556484d561b214b8d285f823a00c31ec849a04c6513afee63e21b98

Contents?: true

Size: 903 Bytes

Versions: 8

Compression:

Stored size: 903 Bytes

Contents

module ActiveRecord
  module Reflection
    class AssociationReflection
      def derive_primary_key
        result = if options[:foreign_key]
          options[:foreign_key]
        elsif belongs_to?
          #CPK
          #"#{name}_id"
          class_name.foreign_key
        elsif options[:as]
          options[:as]
        else
          active_record.name.foreign_key
        end
      end

      def cpk_primary_key
        # Make sure the returned key(s) are an array
        @cpk_primary_key ||= [derive_primary_key].flatten
      end

      def primary_key_name
        @primary_key_name ||= derive_primary_key_name
      end

      def derive_primary_key_name
        result = derive_primary_key

        # CPK
        if result.is_a?(Array)
          result.to_composite_keys.to_s
        else
          result
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
composite_primary_keys-3.0.9 lib/composite_primary_keys/reflection.rb
composite_primary_keys-3.0.8 lib/composite_primary_keys/reflection.rb
composite_primary_keys-3.0.7 lib/composite_primary_keys/reflection.rb
composite_primary_keys-3.0.4 lib/composite_primary_keys/reflection.rb
composite_primary_keys-3.0.3 lib/composite_primary_keys/reflection.rb
composite_primary_keys-3.0.0.b3 lib/composite_primary_keys/reflection.rb
composite_primary_keys-3.0.0.b2 lib/composite_primary_keys/reflection.rb
globe-composite_primary_keys-3.0.1 lib/composite_primary_keys/reflection.rb