Module: ActiveRecord::CreatingForeignKeys::SchemaStatements
- Defined in:
- lib/activerecord/creating_foreign_keys/schema_statements.rb
Instance Method Summary collapse
- #create_table(table_name, options = {}) {|td| ... } ⇒ Object
-
#foreign_key_options(from_table, to_table, options) ⇒ Object
:nodoc:.
Instance Method Details
#create_table(table_name, options = {}) {|td| ... } ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/activerecord/creating_foreign_keys/schema_statements.rb', line 6 def create_table(table_name, = {}) td = create_table_definition table_name, [:temporary], [:options], [:as] if [:id] != false && ![:as] pk = .fetch(:primary_key) do Base.get_primary_key table_name.to_s.singularize end td.primary_key pk, .fetch(:id, :primary_key), end yield td if block_given? if [:force] && table_exists?(table_name) drop_table(table_name, ) end result = execute schema_creation.accept td unless supports_indexes_in_create? td.indexes.each_pair do |column_name, | add_index(table_name, column_name, ) end end result end |
#foreign_key_options(from_table, to_table, options) ⇒ Object
:nodoc:
34 35 36 37 38 39 |
# File 'lib/activerecord/creating_foreign_keys/schema_statements.rb', line 34 def (from_table, to_table, ) # :nodoc: = .dup [:column] ||= foreign_key_column_for(to_table) [:name] ||= foreign_key_name(from_table, ) end |