mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove all cases of manuallly wrapping Arel::Nodes::Quoted
This is no longer required now that we are injecting a type caster object into the Arel table, with the exception of uniqueness validations. Since it calls `ConnectionAdapter#type_cast`, the value has already been cast for the database. We don't want Arel to attempt to cast it further, so we need to continue wrapping it in a quoted node. This can potentially go away when this validator is refactored to make better use of `where` or the predicate builder.
This commit is contained in:
parent
7931c96338
commit
f916aa247b
7 changed files with 15 additions and 34 deletions
|
@ -193,7 +193,6 @@ module ActiveRecord
|
|||
def type_condition(table = arel_table)
|
||||
sti_column = table[inheritance_column]
|
||||
sti_names = ([self] + descendants).map(&:sti_name)
|
||||
sti_names.map! { |v| Arel::Nodes::Quoted.new(v) } # FIXME: Remove this when type casting in Arel is removed (5.1)
|
||||
|
||||
sti_column.in(sti_names)
|
||||
end
|
||||
|
|
|
@ -52,12 +52,7 @@ module ActiveRecord
|
|||
end
|
||||
else
|
||||
enum_for :find_each, options do
|
||||
# FIXME: Remove this when type casting is removed from Arel
|
||||
# (Rails 5.1). We can pass start directly instead.
|
||||
if options[:start]
|
||||
quoted_start = Arel::Nodes::Quoted.new(options[:start])
|
||||
end
|
||||
options[:start] ? where(table[primary_key].gteq(quoted_start)).size : size
|
||||
options[:start] ? where(table[primary_key].gteq(options[:start])).size : size
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -107,15 +102,9 @@ module ActiveRecord
|
|||
start = options[:start]
|
||||
batch_size = options[:batch_size] || 1000
|
||||
|
||||
if start
|
||||
# FIXME: Remove this when type casting is removed from Arel
|
||||
# (Rails 5.1). We can pass start directly instead.
|
||||
quoted_start = Arel::Nodes::Quoted.new(start)
|
||||
end
|
||||
|
||||
unless block_given?
|
||||
return to_enum(:find_in_batches, options) do
|
||||
total = start ? where(table[primary_key].gteq(quoted_start)).size : size
|
||||
total = start ? where(table[primary_key].gteq(start)).size : size
|
||||
(total - 1).div(batch_size) + 1
|
||||
end
|
||||
end
|
||||
|
@ -125,7 +114,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
relation = relation.reorder(batch_order).limit(batch_size)
|
||||
records = start ? relation.where(table[primary_key].gteq(quoted_start)).to_a : relation.to_a
|
||||
records = start ? relation.where(table[primary_key].gteq(start)).to_a : relation.to_a
|
||||
|
||||
while records.any?
|
||||
records_size = records.size
|
||||
|
@ -136,11 +125,7 @@ module ActiveRecord
|
|||
|
||||
break if records_size < batch_size
|
||||
|
||||
# FIXME: Remove this when type casting is removed from Arel
|
||||
# (Rails 5.1). We can pass the offset directly instead.
|
||||
quoted_offset = Arel::Nodes::Quoted.new(primary_key_offset)
|
||||
|
||||
records = relation.where(table[primary_key].gt(quoted_offset)).to_a
|
||||
records = relation.where(table[primary_key].gt(primary_key_offset)).to_a
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ module ActiveRecord
|
|||
value = value.to_s[0, column.limit]
|
||||
end
|
||||
|
||||
# FIXME: Remove this when type casting is removed from Arel (Rails 5.1)
|
||||
value = Arel::Nodes::Quoted.new(value)
|
||||
|
||||
comparison = if !options[:case_sensitive] && value && column.text?
|
||||
|
|
|
@ -25,8 +25,8 @@ class RelationMergingTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_relation_merging_with_arel_equalities_keeps_last_equality
|
||||
devs = Developer.where(Developer.arel_table[:salary].eq(Arel::Nodes::Quoted.new(80000))).merge(
|
||||
Developer.where(Developer.arel_table[:salary].eq(Arel::Nodes::Quoted.new(9000)))
|
||||
devs = Developer.where(Developer.arel_table[:salary].eq(80000)).merge(
|
||||
Developer.where(Developer.arel_table[:salary].eq(9000))
|
||||
)
|
||||
assert_equal [developers(:poor_jamis)], devs.to_a
|
||||
end
|
||||
|
|
|
@ -64,21 +64,21 @@ module ActiveRecord
|
|||
|
||||
def test_has_values
|
||||
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
||||
relation.where! relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
|
||||
relation.where! relation.table[:id].eq(10)
|
||||
assert_equal({:id => 10}, relation.where_values_hash)
|
||||
end
|
||||
|
||||
def test_values_wrong_table
|
||||
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
||||
relation.where! Comment.arel_table[:id].eq(Arel::Nodes::Quoted.new(10))
|
||||
relation.where! Comment.arel_table[:id].eq(10)
|
||||
assert_equal({}, relation.where_values_hash)
|
||||
end
|
||||
|
||||
def test_tree_is_not_traversed
|
||||
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
||||
# FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
|
||||
left = relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
|
||||
right = relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
|
||||
left = relation.table[:id].eq(10)
|
||||
right = relation.table[:id].eq(10)
|
||||
combine = left.and right
|
||||
relation.where! combine
|
||||
assert_equal({}, relation.where_values_hash)
|
||||
|
@ -104,7 +104,7 @@ module ActiveRecord
|
|||
def test_create_with_value_with_wheres
|
||||
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
||||
# FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
|
||||
relation.where! relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
|
||||
relation.where! relation.table[:id].eq(10)
|
||||
relation.create_with_value = {:hello => 'world'}
|
||||
assert_equal({:hello => 'world', :id => 10}, relation.scope_for_create)
|
||||
end
|
||||
|
@ -115,7 +115,7 @@ module ActiveRecord
|
|||
assert_equal({}, relation.scope_for_create)
|
||||
|
||||
# FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
|
||||
relation.where! relation.table[:id].eq(Arel::Nodes::Quoted.new(10))
|
||||
relation.where! relation.table[:id].eq(10)
|
||||
assert_equal({}, relation.scope_for_create)
|
||||
|
||||
relation.create_with_value = {:hello => 'world'}
|
||||
|
|
|
@ -145,13 +145,11 @@ class DefaultScopingTest < ActiveRecord::TestCase
|
|||
assert_equal expected_5, received_5
|
||||
|
||||
expected_6 = Developer.order('salary DESC').collect(&:name)
|
||||
# FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
|
||||
received_6 = DeveloperOrderedBySalary.where(Developer.arel_table['name'].eq(Arel::Nodes::Quoted.new('David'))).unscope(where: :name).collect(&:name)
|
||||
received_6 = DeveloperOrderedBySalary.where(Developer.arel_table['name'].eq('David')).unscope(where: :name).collect(&:name)
|
||||
assert_equal expected_6, received_6
|
||||
|
||||
expected_7 = Developer.order('salary DESC').collect(&:name)
|
||||
# FIXME: Remove the Arel::Nodes::Quoted in Rails 5.1
|
||||
received_7 = DeveloperOrderedBySalary.where(Developer.arel_table[:name].eq(Arel::Nodes::Quoted.new('David'))).unscope(where: :name).collect(&:name)
|
||||
received_7 = DeveloperOrderedBySalary.where(Developer.arel_table[:name].eq('David')).unscope(where: :name).collect(&:name)
|
||||
assert_equal expected_7, received_7
|
||||
end
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class Author < ActiveRecord::Base
|
|||
-> { where(title: 'Welcome to the weblog').where('comments_count = ?', 1) },
|
||||
class_name: 'Post'
|
||||
has_many :welcome_posts_with_comments,
|
||||
-> { where(title: 'Welcome to the weblog').where(Post.arel_table[:comments_count].gt(Arel::Nodes::Quoted.new(0))) },
|
||||
-> { where(title: 'Welcome to the weblog').where(Post.arel_table[:comments_count].gt(0)) },
|
||||
class_name: 'Post'
|
||||
|
||||
has_many :comments_desc, -> { order('comments.id DESC') }, :through => :posts, :source => :comments
|
||||
|
|
Loading…
Reference in a new issue