Module: FriendlyFk::SchemaStatements

Defined in:
lib/friendly_fk.rb

Overview

Overrides the default foreign key name with a readable one built from the parent and child table names plus the referencing column(s), while delegating column resolution (including composite primary keys) to ActiveRecord. Folding the column in keeps names unique when several foreign keys connect the same table pair. Prepended so super keeps working across ActiveRecord versions.

Instance Method Summary collapse

Instance Method Details

#foreign_key_options(from_table, to_table, options) ⇒ Object

:nodoc:



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

def foreign_key_options(from_table, to_table, options) # :nodoc:
  name_given = options.key?(:name)
  options = super
  options[:name] = friendly_fk_name(from_table, to_table, options[:column]) unless name_given
  options
end