diff options
author | George Millo <georgejulianmillo@gmail.com> | 2016-02-11 11:25:16 -0700 |
---|---|---|
committer | George Millo <georgejulianmillo@gmail.com> | 2016-02-15 16:04:34 -0700 |
commit | aedde2a33d23252053d4ba6ebdf5f0b2d000aa4b (patch) | |
tree | f91d7a62fd371c5932c48e47d6827815873cad50 /activerecord/lib | |
parent | 156c2cb571af8c2049e61c50232084a9351f428b (diff) | |
download | rails-aedde2a33d23252053d4ba6ebdf5f0b2d000aa4b.tar.gz rails-aedde2a33d23252053d4ba6ebdf5f0b2d000aa4b.tar.bz2 rails-aedde2a33d23252053d4ba6ebdf5f0b2d000aa4b.zip |
Let t.foreign_key use the same `to_table` twice
Previously if you used `t.foreign_key` twice within the same
`create_table` block using the same `to_table`, all statements except
the final one would fail silently. For example, the following code:
def change
create_table :flights do |t|
t.integer :from_id, index: true, null: false
t.integer :to_id, index: true, null: false
t.foreign_key :airports, column: :from_id
t.foreign_key :airports, column: :to_id
end
end
Would only create one foreign key, on the column `from_id`.
This commit allows multiple foreign keys to the same table to be created
within one `create_table` block.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index cb10ca9929..4f97c7c065 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -212,7 +212,7 @@ module ActiveRecord def initialize(name, temporary, options, as = nil) @columns_hash = {} @indexes = {} - @foreign_keys = {} + @foreign_keys = [] @primary_keys = nil @temporary = temporary @options = options @@ -330,7 +330,7 @@ module ActiveRecord end def foreign_key(table_name, options = {}) # :nodoc: - foreign_keys[table_name] = options + foreign_keys.push([table_name, options]) end # Appends <tt>:datetime</tt> columns <tt>:created_at</tt> and |