Sha256: 4f5a0dc3765408530aee751eacedf274377323656018089fc57c4555ddfe2fa0

Contents?: true

Size: 691 Bytes

Versions: 8

Compression:

Stored size: 691 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

8 entries across 8 versions & 1 rubygems

Version Path
composite_primary_keys-8.1.8 lib/composite_primary_keys/associations/singular_association.rb
composite_primary_keys-8.1.7 lib/composite_primary_keys/associations/singular_association.rb
composite_primary_keys-8.1.6 lib/composite_primary_keys/associations/singular_association.rb
composite_primary_keys-8.1.5 lib/composite_primary_keys/associations/singular_association.rb
composite_primary_keys-8.1.4 lib/composite_primary_keys/associations/singular_association.rb
composite_primary_keys-8.1.3 lib/composite_primary_keys/associations/singular_association.rb
composite_primary_keys-8.1.2 lib/composite_primary_keys/associations/singular_association.rb
composite_primary_keys-8.1.1 lib/composite_primary_keys/associations/singular_association.rb