Module: ActiveRecord::ConnectionAdapters::SchemaStatements

Defined in:
lib/friendly_fk.rb

Instance Method Summary collapse

Instance Method Details

#foreign_key_name(from_table, options) ⇒ Object



16
17
18
19
20
# File 'lib/friendly_fk.rb', line 16

def foreign_key_name(from_table, options)
  options.fetch(:name) do
    "fk_#{from_table}__#{options[:to_table]}"
  end
end

#foreign_key_options(from_table, to_table, options) ⇒ Object

:nodoc:



8
9
10
11
12
13
14
# File 'lib/friendly_fk.rb', line 8

def foreign_key_options(from_table, to_table, options) # :nodoc:
  options = options.dup
  options[:to_table] = to_table
  options[:column] ||= foreign_key_column_for(to_table)
  options[:name]   ||= foreign_key_name(from_table, options)
  options
end