Sha256: dd1e64eeea0f25894cc0010a109b9979d3b2c6b91dd122ae9475d97a3fa6d827

Contents?: true

Size: 930 Bytes

Versions: 12

Compression:

Stored size: 930 Bytes

Contents

module ActiveType

  module ChangeAssociation

    extend ActiveSupport::Concern

    module ClassMethods

      def change_association(association_name, new_scope, new_options = nil)
        if (existing_association = self.reflect_on_association(association_name))
          if new_scope.is_a?(Hash)
            new_options = new_scope
            new_scope = nil
          end
          original_options = existing_association.options
          if ActiveRecord::VERSION::MAJOR > 3
            new_scope ||= existing_association.scope
            public_send(existing_association.macro, association_name, new_scope, **original_options.merge(new_options))
          else
            public_send(existing_association.macro, association_name, **original_options.merge(new_options))
          end
        else
          raise ArgumentError, "unrecognized association `#{association_name}`"
        end
      end

    end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
active_type-2.3.0 lib/active_type/change_association.rb
active_type-2.2.0 lib/active_type/change_association.rb
active_type-2.1.2 lib/active_type/change_association.rb
active_type-2.1.1 lib/active_type/change_association.rb
active_type-2.1.0 lib/active_type/change_association.rb
active_type-2.0 lib/active_type/change_association.rb
active_type-1.10.1 lib/active_type/change_association.rb
active_type-1.10.0 lib/active_type/change_association.rb
active_type-1.9.1 lib/active_type/change_association.rb
active_type-1.9.0 lib/active_type/change_association.rb
active_type-1.8.0 lib/active_type/change_association.rb
active_type-1.7.0 lib/active_type/change_association.rb