1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

push up bind params on "simple" subquery calculations

bind parameters we not being propogated to simple subquery calculation
calls. This fixes it
This commit is contained in:
Aaron Patterson 2014-05-02 11:52:37 -07:00
parent dece005f0a
commit 3d87c26845
2 changed files with 11 additions and 3 deletions

View file

@ -242,7 +242,7 @@ module ActiveRecord
return 0 if relation.limit_value == 0 return 0 if relation.limit_value == 0
query_builder = build_count_subquery(relation, column_name, distinct) query_builder = build_count_subquery(relation, column_name, distinct)
bind_values = relation.bind_values bind_values = query_builder.bind_values + relation.bind_values
else else
column = aggregate_column(column_name) column = aggregate_column(column_name)
@ -389,9 +389,11 @@ module ActiveRecord
aliased_column = aggregate_column(column_name == :all ? 1 : column_name).as(column_alias) aliased_column = aggregate_column(column_name == :all ? 1 : column_name).as(column_alias)
relation.select_values = [aliased_column] relation.select_values = [aliased_column]
subquery = relation.arel.as(subquery_alias) arel = relation.arel
subquery = arel.as(subquery_alias)
sm = Arel::SelectManager.new relation.engine sm = Arel::SelectManager.new relation.engine
sm.bind_values = arel.bind_values
select_value = operation_over_aggregate_column(column_alias, 'count', distinct) select_value = operation_over_aggregate_column(column_alias, 'count', distinct)
sm.project(select_value).from(subquery) sm.project(select_value).from(subquery)
end end

View file

@ -43,12 +43,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :categories, :companies, :developers, :projects, fixtures :accounts, :categories, :companies, :developers, :projects,
:developers_projects, :topics, :authors, :comments, :developers_projects, :topics, :authors, :comments,
:people, :posts, :readers, :taggings, :cars, :essays, :people, :posts, :readers, :taggings, :cars, :essays,
:categorizations, :jobs :categorizations, :jobs, :tags, :posts
def setup def setup
Client.destroyed_client_ids.clear Client.destroyed_client_ids.clear
end end
def test_sti_subselect_count
tag = Tag.first
len = Post.tagged_with(tag.id).limit(10).size
assert_operator len, :>, 0
end
def test_anonymous_has_many def test_anonymous_has_many
developer = Class.new(ActiveRecord::Base) { developer = Class.new(ActiveRecord::Base) {
self.table_name = 'developers' self.table_name = 'developers'