Sha256: ec6fea73d5a6f983b70cd8d39bdb866e74cd28ddcbd2ad5b90e82d73cd1eaf4e

Contents?: true

Size: 673 Bytes

Versions: 1

Compression:

Stored size: 673 Bytes

Contents

module CompositePrimaryKeys
  module SingularAssociation
    extend ActiveSupport::Concern
    included do
      def get_records_with_cpk_support
        cpk_applies = (target && target.composite?) ||
          (owner && owner.composite?) ||
          (options[:primary_key] && options[:primary_key].kind_of?(Array)) || 
          (options[:foreign_key] && options[:foreign_key].kind_of?(Array))
        return scope.limit(1).to_a if cpk_applies
        get_records_without_cpk_support
      end
      alias_method_chain :get_records, :cpk_support
    end
  end
end

ActiveRecord::Associations::SingularAssociation.send(:include, CompositePrimaryKeys::SingularAssociation)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
composite_primary_keys-8.1.0 lib/composite_primary_keys/associations/singular_association.rb