Sha256: 1c7e1a9bdb9d71b7b349ea4b158c6aa12441f3565d258a1f10a3379d59f9756d

Contents?: true

Size: 961 Bytes

Versions: 15

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

require 'active_support/concern'
require 'active_record/associations'
require 'active_record/associations/association'

module BetterRecord
  module AssociationsExtensions
    module AssociationExtensions
      extend ActiveSupport::Concern

      included do
        def creation_attributes
          attributes = {}

          if (reflection.has_one? || reflection.collection?) && !options[:through]
            attributes[reflection.foreign_key] = owner[reflection.active_record_primary_key]

            if reflection.type
              attributes[reflection.type] = get_type_value
            end
          end

          attributes
        end

        def get_type_value
          BetterRecord::PolymorphicOverride.polymorphic_value(owner.class, reflection.options)
        end
      end
    end
  end
end

ActiveRecord::Associations::Association.send(:include, BetterRecord::AssociationsExtensions::AssociationExtensions)

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
better_record-0.25.2 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.25.1 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.25.0 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.24.4 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.24.3 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.23.7 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.23.6 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.23.5 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.23.4 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.23.3 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.22.9 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.22.8 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.22.7 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.22.6 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb
better_record-0.22.5 lib/better_record/concerns/active_record_extensions/associations_extensions/association_extension.rb