Sha256: 55f961ed4cc801151a609572d7676516d68bcac11d49788d9621f9bac8a033f7

Contents?: true

Size: 892 Bytes

Versions: 79

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord::Associations
  module ForeignAssociation # :nodoc:
    def foreign_key_present?
      if reflection.klass.primary_key
        owner.attribute_present?(reflection.active_record_primary_key)
      else
        false
      end
    end

    def nullified_owner_attributes
      Hash.new.tap do |attrs|
        attrs[reflection.foreign_key] = nil
        attrs[reflection.type] = nil if reflection.type.present?
      end
    end

    private
      # Sets the owner attributes on the given record
      def set_owner_attributes(record)
        return if options[:through]

        key = owner._read_attribute(reflection.join_foreign_key)
        record._write_attribute(reflection.join_primary_key, key)

        if reflection.type
          record._write_attribute(reflection.type, owner.class.polymorphic_name)
        end
      end
  end
end

Version data entries

79 entries across 75 versions & 7 rubygems

Version Path
activerecord-7.0.8.7 lib/active_record/associations/foreign_association.rb
activerecord-7.0.8.6 lib/active_record/associations/foreign_association.rb
activerecord-6.1.7.10 lib/active_record/associations/foreign_association.rb
activerecord-6.1.7.9 lib/active_record/associations/foreign_association.rb
activerecord-7.0.8.5 lib/active_record/associations/foreign_association.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/active_record/associations/foreign_association.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/associations/foreign_association.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/associations/foreign_association.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/associations/foreign_association.rb
activerecord-7.0.8.4 lib/active_record/associations/foreign_association.rb
activerecord-6.1.7.8 lib/active_record/associations/foreign_association.rb
activerecord-7.0.8.1 lib/active_record/associations/foreign_association.rb
activerecord-6.1.7.7 lib/active_record/associations/foreign_association.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.2.3/lib/active_record/associations/foreign_association.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/associations/foreign_association.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/associations/foreign_association.rb
activerecord-7.0.8 lib/active_record/associations/foreign_association.rb
activerecord-7.0.7.2 lib/active_record/associations/foreign_association.rb
activerecord-6.1.7.6 lib/active_record/associations/foreign_association.rb
activerecord-7.0.7.1 lib/active_record/associations/foreign_association.rb