Module: RedhillonrailsCore::ActiveRecord::ConnectionAdapters::TableDefinition

Defined in:
lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb', line 5

def self.included(base)
  base.class_eval do
    attr_accessor :name
    alias_method_chain :initialize, :redhillonrails_core
    alias_method_chain :to_sql, :redhillonrails_core
  end
end

Instance Method Details

#foreign_key(column_names, references_table_name, references_column_names, options = {}) ⇒ Object



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

def foreign_key(column_names, references_table_name, references_column_names, options = {})
  @foreign_keys << ForeignKeyDefinition.new(options[:name], name, column_names,
      ::ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names,
      options[:on_update], options[:on_delete], options[:deferrable])
  self
end

#initialize_with_redhillonrails_core(*args) ⇒ Object



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

def initialize_with_redhillonrails_core(*args)
  initialize_without_redhillonrails_core(*args)
  @foreign_keys = []
end

#to_sql_with_redhillonrails_coreObject



25
26
27
28
29
# File 'lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb', line 25

def to_sql_with_redhillonrails_core
  sql = to_sql_without_redhillonrails_core
  sql << ', ' << @foreign_keys * ', ' unless @foreign_keys.empty? || ::ActiveRecord::Schema.defining?
  sql
end