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



21
22
23
24
25
26
# File 'lib/schema_plus/core/active_record/connection_adapters/table_definition.rb', line 21

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

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



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

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

#index(*args) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/schema_plus/core/active_record/connection_adapters/table_definition.rb', line 28

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



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

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