mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #14143 from derekprior/dp-compound-index-ordering
Use type column first in multi-column indexes Conflicts: activerecord/CHANGELOG.md
This commit is contained in:
commit
ffed7acd8e
5 changed files with 9 additions and 5 deletions
|
@ -1,3 +1,7 @@
|
|||
* Use type column first in multi-column indexes created with `add-reference`.
|
||||
|
||||
*Derek Prior*
|
||||
|
||||
* Fix `Relation.rewhere` to work with Range values.
|
||||
|
||||
*Dan Olson*
|
||||
|
|
|
@ -312,7 +312,7 @@ module ActiveRecord
|
|||
args.each do |col|
|
||||
column("#{col}_id", type, options)
|
||||
column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
|
||||
index(polymorphic ? %w(id type).map { |t| "#{col}_#{t}" } : "#{col}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
|
||||
index(polymorphic ? %w(type id).map { |t| "#{col}_#{t}" } : "#{col}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
|
||||
end
|
||||
end
|
||||
alias :belongs_to :references
|
||||
|
|
|
@ -629,7 +629,7 @@ module ActiveRecord
|
|||
type = options.delete(:type) || :integer
|
||||
add_column(table_name, "#{ref_name}_id", type, options)
|
||||
add_column(table_name, "#{ref_name}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) if polymorphic
|
||||
add_index(table_name, polymorphic ? %w[id type].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
|
||||
add_index(table_name, polymorphic ? %w[type id].map{ |t| "#{ref_name}_#{t}" } : "#{ref_name}_id", index_options.is_a?(Hash) ? index_options : {}) if index_options
|
||||
end
|
||||
alias :add_belongs_to :add_reference
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ module ActiveRecord
|
|||
t.references :foo, :polymorphic => true, :index => true
|
||||
end
|
||||
|
||||
assert connection.index_exists?(table_name, [:foo_id, :foo_type], :name => :index_testings_on_foo_id_and_foo_type)
|
||||
assert connection.index_exists?(table_name, [:foo_type, :foo_id], name: :index_testings_on_foo_type_and_foo_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -93,7 +93,7 @@ module ActiveRecord
|
|||
t.references :foo, :polymorphic => true, :index => true
|
||||
end
|
||||
|
||||
assert connection.index_exists?(table_name, [:foo_id, :foo_type], :name => :index_testings_on_foo_id_and_foo_type)
|
||||
assert connection.index_exists?(table_name, [:foo_type, :foo_id], name: :index_testings_on_foo_type_and_foo_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ module ActiveRecord
|
|||
|
||||
def test_creates_polymorphic_index
|
||||
add_reference table_name, :taggable, polymorphic: true, index: true
|
||||
assert index_exists?(table_name, [:taggable_id, :taggable_type])
|
||||
assert index_exists?(table_name, [:taggable_type, :taggable_id])
|
||||
end
|
||||
|
||||
def test_creates_reference_type_column_with_default
|
||||
|
|
Loading…
Reference in a new issue