Module: SchemaPlus::Core::ActiveRecord::ConnectionAdapters::TableDefinition

Defined in:
lib/schema_plus/core/active_record/connection_adapters/table_definition.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(name, options = {}) ⇒ Object



19
20
21
22
23
# File 'lib/schema_plus/core/active_record/connection_adapters/table_definition.rb', line 19

def belongs_to(name, options = {})
  SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: "#{name}_id", type: :reference, options: options.deep_dup) do |env|
    super env.column_name.sub(/_id$/, ''), env.options
  end
end

#column(name, type, options = {}) ⇒ Object



7
8
9
10
11
# File 'lib/schema_plus/core/active_record/connection_adapters/table_definition.rb', line 7

def column(name, type, options = {})
  SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: name, type: type, options: options.deep_dup) do |env|
    super env.column_name, env.type, env.options
  end
end

#index(*args) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/schema_plus/core/active_record/connection_adapters/table_definition.rb', line 25

def index(*args)
  options = args.extract_options!
  column_name = args.first
  SchemaMonkey::Middleware::Migration::Index.start(caller: self, operation: :define, table_name: self.name, column_names: column_name, options: options.deep_dup) do |env|
    super env.column_names, env.options
  end
end

#references(name, options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/schema_plus/core/active_record/connection_adapters/table_definition.rb', line 13

def references(name, options = {})
  SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :define, table_name: self.name, column_name: "#{name}_id", type: :reference, options: options.deep_dup) do |env|
    super env.column_name.sub(/_id$/, ''), env.options
  end
end