mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Don't interpret decimals as table names in ActiveRecord::Associations::ClassMethods#references_eager_loaded_tables? [#532 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
committed by
Pratik Naik
parent
3724dafe71
commit
8622787f87
6
activerecord/lib/active_record/associations.rb
Normal file → Executable file
6
activerecord/lib/active_record/associations.rb
Normal file → Executable file
@@ -1679,19 +1679,19 @@ module ActiveRecord
|
||||
else all << cond
|
||||
end
|
||||
end
|
||||
conditions.join(' ').scan(/([\.\w]+).?\./).flatten
|
||||
conditions.join(' ').scan(/([\.a-zA-Z_]+).?\./).flatten
|
||||
end
|
||||
|
||||
def order_tables(options)
|
||||
order = [options[:order], scope(:find, :order) ].join(", ")
|
||||
return [] unless order && order.is_a?(String)
|
||||
order.scan(/([\.\w]+).?\./).flatten
|
||||
order.scan(/([\.a-zA-Z_]+).?\./).flatten
|
||||
end
|
||||
|
||||
def selects_tables(options)
|
||||
select = options[:select]
|
||||
return [] unless select && select.is_a?(String)
|
||||
select.scan(/"?([\.\w]+)"?.?\./).flatten
|
||||
select.scan(/"?([\.a-zA-Z_]+)"?.?\./).flatten
|
||||
end
|
||||
|
||||
# Checks if the conditions reference a table other than the current model table
|
||||
|
||||
@@ -559,6 +559,13 @@ class EagerAssociationTest < ActiveRecord::TestCase
|
||||
assert_nothing_raised { Post.find(:all, :include => 'comments') }
|
||||
end
|
||||
|
||||
def test_eager_with_floating_point_numbers
|
||||
assert_queries(2) do
|
||||
# Before changes, the floating point numbers will be interpreted as table names and will cause this to run in one query
|
||||
Comment.find :all, :conditions => "123.456 = 123.456", :include => :post
|
||||
end
|
||||
end
|
||||
|
||||
def test_preconfigured_includes_with_belongs_to
|
||||
author = posts(:welcome).author_with_posts
|
||||
assert_no_queries {assert_equal 5, author.posts.size}
|
||||
|
||||
Reference in New Issue
Block a user