Sha256: 9915bda8c6a59086ed3e30a6d1920e6fbf2d6ce5a131b931c544c470679cf863

Contents?: true

Size: 985 Bytes

Versions: 2

Compression:

Stored size: 985 Bytes

Contents

module RedHillConsulting::ForeignKeyMigrations::ActiveRecord::ConnectionAdapters
  module AbstractAdapter
    def self.included(base)
      base.class_eval do
        alias_method_chain :initialize, :foreign_key_migrations unless method_defined?(:initialize_without_foreign_key_migrations)
      end
    end

    def initialize_with_foreign_key_migrations(*args)
      initialize_without_foreign_key_migrations(*args)
      self.class.class_eval do
        alias_method_chain :add_column, :foreign_key_migrations unless method_defined?(:add_column_without_foreign_key_migrations)
      end
    end

    def add_column_with_foreign_key_migrations(table_name, column_name, type, options = {})
      add_column_without_foreign_key_migrations(table_name, column_name, type, options)
      references = ActiveRecord::Base.references(table_name, column_name, options)
      add_foreign_key(table_name, column_name, references.first, references.last, options) if references
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
advertnet-1.0.0 vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/abstract_adapter.rb
advertnet-1.0.1 vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/abstract_adapter.rb