Sha256: 736ceb21a033b76dd789eecb15e423db96c45ad289a26ec63893bc4b527d2a92

Contents?: true

Size: 926 Bytes

Versions: 10

Compression:

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

10 entries across 10 versions & 1 rubygems

Version Path
active_type-1.6.0 lib/active_type/change_association.rb
active_type-1.5.0 lib/active_type/change_association.rb
active_type-1.4.2 lib/active_type/change_association.rb
active_type-1.4.1 lib/active_type/change_association.rb
active_type-1.4.0 lib/active_type/change_association.rb
active_type-1.3.2 lib/active_type/change_association.rb
active_type-1.3.1 lib/active_type/change_association.rb
active_type-1.3.0 lib/active_type/change_association.rb
active_type-1.2.1 lib/active_type/change_association.rb
active_type-1.2.0 lib/active_type/change_association.rb