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



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

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



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

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(column_name, **options) ⇒ Object



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

def index(column_name, options = {})
  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



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

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