提交 f106e2c5 编写于 作者: R Rick Olson

Fix bug where calculations with long alias names return null. [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4269 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 09095c72
*SVN*
* Fix bug where calculations with long alias names return null. [Rick]
* Raise error when trying to add to a has_many :through association. Use the Join Model instead. [Rick]
@post.tags << @tag # BAD
......
......@@ -172,10 +172,10 @@ def construct_calculation_sql(operation, column_name, options) #:nodoc:
end
add_joins!(sql, options, scope)
add_conditions!(sql, options[:conditions], scope)
sql << " GROUP BY #{options[:group_field]}" if options[:group]
sql << " HAVING #{options[:having]}" if options[:group] && options[:having]
sql << " ORDER BY #{options[:order]}" if options[:order]
add_limited_ids_condition!(sql, options, join_dependency) if join_dependency && !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
sql << " GROUP BY #{options[:group_field]} " if options[:group]
sql << " HAVING #{options[:having]} " if options[:group] && options[:having]
sql << " ORDER BY #{options[:order]} " if options[:order]
add_limit!(sql, options, scope)
sql << ')' if use_workaround
sql
......@@ -222,7 +222,7 @@ def validate_calculation_options(operation, options = {})
# count(distinct users.id) #=> count_distinct_users_id
# count(*) #=> count_all
def column_alias_for(*keys)
keys.join(' ').downcase.gsub(/\*/, 'all').gsub(/\W+/, ' ').strip.gsub(/ +/, '_')
connection.table_alias_for(keys.join(' ').downcase.gsub(/\*/, 'all').gsub(/\W+/, ' ').strip.gsub(/ +/, '_'))
end
def column_for(field)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册