Module: SchemaPlus::ActiveRecord::ConnectionAdapters::SchemaStatements

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



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

def self.included(base) #:nodoc:
  base.class_eval do
    alias_method_chain :create_table, :schema_plus
  end
end

Instance Method Details

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

:method: create_table

SchemaPlus extends SchemaStatements::create_table to allow you to specify configuration options per table. Pass them in as a hash keyed by configuration set (see SchemaPlus::Config), for example:

create_table :widgets, :foreign_keys => {:auto_create => true, :on_delete => :cascade} do |t|
   ...
end


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/schema_plus/active_record/connection_adapters/schema_statements.rb', line 19

def create_table_with_schema_plus(table, options = {})
  options = options.dup
  config_options = {}
  options.keys.each { |key| config_options[key] = options.delete(key) if SchemaPlus.config.class.attributes.include? key }

  indexes = []
  create_table_without_schema_plus(table, options) do |table_definition|
    table_definition.schema_plus_config = SchemaPlus.config.merge(config_options)
    table_definition.name = table
    yield table_definition if block_given?
    indexes = table_definition.indexes
  end
  indexes.each do |index|
    add_index(table, index.columns, index.opts)
  end


end