diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-04-25 18:53:19 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-04-25 18:53:19 +0000 |
commit | f106e2c5c809ca355ce68a3e15718a17cd930680 (patch) | |
tree | d83ad8ef58d296e44df33f450dcbce56a5d12b27 /activerecord | |
parent | 09095c720406d80f5faf482a0dd840a290f1781d (diff) | |
download | rails-f106e2c5c809ca355ce68a3e15718a17cd930680.tar.gz rails-f106e2c5c809ca355ce68a3e15718a17cd930680.tar.bz2 rails-f106e2c5c809ca355ce68a3e15718a17cd930680.zip |
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
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/calculations.rb | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index b5d6da9dc8..a07b82632d 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *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 diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 9a747f661b..83bf279785 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -172,10 +172,10 @@ module ActiveRecord 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 @@ module ActiveRecord # 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) |