Module: SchemaPlus::ForeignKeys::ActiveRecord::Migration::CommandRecorder

Defined in:
lib/schema_plus/foreign_keys/active_record/migration/command_recorder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#schema_plus_foreign_keys_configObject

:nodoc:



8
9
10
# File 'lib/schema_plus/foreign_keys/active_record/migration/command_recorder.rb', line 8

def schema_plus_foreign_keys_config
  @schema_plus_foreign_keys_config
end

Instance Method Details

#add_reference(table_name, ref_name, options = {}) ⇒ Object

seems like this is fixing a rails bug:

change_table foo, bulk: true { |t| t.references :bar }

results in an ‘unknown method :add_reference_sql’ (with mysql2)

should track it down separately and submit a patch/fix to rails



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/schema_plus/foreign_keys/active_record/migration/command_recorder.rb', line 16

def add_reference(table_name, ref_name, options = {}) #:nodoc:
  polymorphic = options.delete(:polymorphic)
  options[:references] = nil if polymorphic
  # ugh.  copying and pasting code from ::ActiveRecord::ConnectionAdapters::SchemaStatements#add_reference
  index_options = options.delete(:index)
  add_column(table_name, "#{ref_name}_id", :integer, **options)
  add_column(table_name, "#{ref_name}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
  add_index(table_name, polymorphic ? %w[id type].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options

  self
end