Sha256: 3f836776e48e94b15e3ef34a4626c54cec82417fcad4d041bc409ef70b809321

Contents?: true

Size: 816 Bytes

Versions: 1

Compression:

Stored size: 816 Bytes

Contents

module ActiveRecord
  module Reflection
    class AssociationReflection
      def derive_primary_key
        if options[:foreign_key]
          options[:foreign_key]
        elsif belongs_to?
          "#{name}_id"
        elsif options[:as]
          "#{options[:as]}_id"
        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

1 entries across 1 versions & 1 rubygems

Version Path
composite_primary_keys-3.1.11 lib/composite_primary_keys/reflection.rb