Class: ActiveRecord::ConnectionAdapters::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_foreign_keys.rb

Instance Method Summary collapse

Instance Method Details

#references_with_foreign_key(*args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/active_record_foreign_keys.rb', line 34

def references_with_foreign_key(*args)
  options = args.extract_options!
  cols = args.dup
  fk_options = options.delete(:foreign_key) || false
  references_without_foreign_key(*(args << options))
  unless options[:polymorphic] || fk_options == false
    fk_options = {} unless fk_options.is_a?(Hash)
    cols.each { |col| @base.add_foreign_key(@table_name, "#{col}_id", col.to_s.pluralize, "id", fk_options) }
  end
end