aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliot Winkler <elliot.winkler@gmail.com>2011-07-18 14:56:07 -0600
committerElliot Winkler <elliot.winkler@gmail.com>2011-07-18 14:56:37 -0600
commit0e1d617b8b869426960ec25b62620fe1599cb5e6 (patch)
tree37878130e12ad19210d45239c4f4f1833c76a869
parentb475f74da5ec2ac4048f70d9063a1d4c0d63b546 (diff)
downloadrails-0e1d617b8b869426960ec25b62620fe1599cb5e6.tar.gz
rails-0e1d617b8b869426960ec25b62620fe1599cb5e6.tar.bz2
rails-0e1d617b8b869426960ec25b62620fe1599cb5e6.zip
ActiveRecord: Fix eager loading so that giving a blank order clause generates valid SQL
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
-rw-r--r--activerecord/test/cases/associations/eager_test.rb12
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 283115a448..220ead4edb 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -243,7 +243,7 @@ module ActiveRecord
end
def construct_limited_ids_condition(relation)
- orders = relation.order_values
+ orders = relation.order_values.map(&:presence).compact
values = @klass.connection.distinct("#{@klass.connection.quote_table_name table_name}.#{primary_key}", orders)
relation = relation.dup
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index f1d061133c..c6e451fc57 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -1048,4 +1048,16 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_not_equal 0, post.comments.to_a.count
end
end
+
+ def test_join_eager_with_empty_order_should_generate_valid_sql
+ assert_nothing_raised(ActiveRecord::StatementInvalid) do
+ Post.includes(:comments).order("").where(:comments => {:body => "Thank you for the welcome"}).first
+ end
+ end
+
+ def test_join_eager_with_nil_order_should_generate_valid_sql
+ assert_nothing_raised(ActiveRecord::StatementInvalid) do
+ Post.includes(:comments).order(nil).where(:comments => {:body => "Thank you for the welcome"}).first
+ end
+ end
end