Class: ActiveRecord::ConnectionAdapters::TableDefinition

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



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/active_record_foreign_keys.rb', line 6

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
    @table_statements ||= []
    fk_options = {} unless fk_options.is_a?(Hash)
    cols.each do |col|
      @table_statements << @base.foreign_key_sql(@table_name, "#{col}_id", col.to_s.pluralize, "id", fk_options)
    end
  end
end

#to_sql_with_foreign_keyObject



21
22
23
24
25
26
27
28
29
# File 'lib/active_record_foreign_keys.rb', line 21

def to_sql_with_foreign_key
  col_defs = to_sql_without_foreign_key
  if @table_statements.is_a?(Array) && @table_statements.size > 0
    sql = col_defs + ", " + (@table_statements * ", ")
  else
    sql = col_defs
  end
  sql
end