mirror of https://github.com/rails/rails
Merge pull request #23797 from kamipo/case_sensitive_comparison_for_non_string_column
The BINARY Operator is only needed for string columns
This commit is contained in:
commit
eefcc78f7a
|
@ -607,10 +607,10 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def case_sensitive_comparison(table, attribute, column, value)
|
||||
if value.nil? || column.case_sensitive?
|
||||
super
|
||||
else
|
||||
if !value.nil? && column.collation && !column.case_sensitive?
|
||||
table[attribute].eq(Arel::Nodes::Bin.new(Arel::Nodes::BindParam.new))
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -51,4 +51,13 @@ class Mysql2CaseSensitivityTest < ActiveRecord::Mysql2TestCase
|
|||
cs_uniqueness_query = queries.detect { |q| q.match(/string_cs_column/) }
|
||||
assert_no_match(/binary/i, cs_uniqueness_query)
|
||||
end
|
||||
|
||||
def test_case_sensitive_comparison_for_binary_column
|
||||
CollationTest.validates_uniqueness_of(:binary_column, case_sensitive: true)
|
||||
CollationTest.create!(binary_column: 'A')
|
||||
invalid = CollationTest.new(binary_column: 'A')
|
||||
queries = assert_sql { invalid.save }
|
||||
bin_uniqueness_query = queries.detect { |q| q.match(/binary_column/) }
|
||||
assert_no_match(/\bBINARY\b/, bin_uniqueness_query)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,6 +33,7 @@ ActiveRecord::Schema.define do
|
|||
create_table :collation_tests, id: false, force: true do |t|
|
||||
t.string :string_cs_column, limit: 1, collation: 'utf8_bin'
|
||||
t.string :string_ci_column, limit: 1, collation: 'utf8_general_ci'
|
||||
t.binary :binary_column, limit: 1
|
||||
end
|
||||
|
||||
ActiveRecord::Base.connection.execute <<-SQL
|
||||
|
|
Loading…
Reference in New Issue