aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-07-01 21:41:41 -0400
committerJosé Valim <jose.valim@gmail.com>2010-07-13 22:03:35 +0200
commitedb5401039ee15c37b201244c5dbf660bed51fb4 (patch)
tree785330f325da5180afdde007b3769db87a29bc30 /activerecord/lib/active_record/associations
parentf4fbc2c1f943ff11776b2c7c34df6bcbe655a4e5 (diff)
downloadrails-edb5401039ee15c37b201244c5dbf660bed51fb4.tar.gz
rails-edb5401039ee15c37b201244c5dbf660bed51fb4.tar.bz2
rails-edb5401039ee15c37b201244c5dbf660bed51fb4.zip
count method should not take options if it is operated on has_many association which has finder_sql or counter_sql
[#2395 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 615b7d2719..1c3a6b56f3 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -183,10 +183,13 @@ module ActiveRecord
# descendant's +construct_sql+ method will have set :counter_sql automatically.
# Otherwise, construct options and pass them with scope to the target class's +count+.
def count(column_name = nil, options = {})
- if @reflection.options[:counter_sql]
+ column_name, options = nil, column_name if column_name.is_a?(Hash)
+
+ if @reflection.options[:counter_sql] && !options.blank?
+ raise ArgumentError, "If finder_sql/counter_sql is used then options cannot be passed"
+ elsif @reflection.options[:counter_sql]
@reflection.klass.count_by_sql(@counter_sql)
else
- column_name, options = nil, column_name if column_name.is_a?(Hash)
if @reflection.options[:uniq]
# This is needed because 'SELECT count(DISTINCT *)..' is not valid SQL.