Module: AutomaticForeignKey::ActiveRecord::ConnectionAdapters::SchemaStatements

Defined in:
lib/automatic_foreign_key/active_record/connection_adapters/schema_statements.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/automatic_foreign_key/active_record/connection_adapters/schema_statements.rb', line 4

def self.included(base)
  base.class_eval do
    alias_method_chain :create_table, :automatic_foreign_key
  end
end

Instance Method Details

#create_table_with_automatic_foreign_key(table, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/automatic_foreign_key/active_record/connection_adapters/schema_statements.rb', line 10

def create_table_with_automatic_foreign_key(table, options = {})
  indices = nil
  create_table_without_automatic_foreign_key(table, options) do |table_definition|
    yield table_definition if block_given?
    indices = table_definition.indices
  end
  indices.each do |column_name, index_options|
    column_names = [column_name] + Array.wrap(index_options.delete(:with))
    add_index(table, column_names, index_options)
  end 
end