diff options
author | kal <kalrover.ngo@gmail.com> | 2015-10-16 02:18:36 +0000 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-10-20 15:25:05 -0200 |
commit | dda4f608902752c5071809cedbe675086f0669be (patch) | |
tree | dc2b88547400cfea4c8b5ced78b368e7b3b3846e /activerecord | |
parent | d68e81afa0e5b2697755a34e9b1d11b9b5d1df9d (diff) | |
download | rails-dda4f608902752c5071809cedbe675086f0669be.tar.gz rails-dda4f608902752c5071809cedbe675086f0669be.tar.bz2 rails-dda4f608902752c5071809cedbe675086f0669be.zip |
Changed the order of Association constraints from where->order->unscope to unscope->where->order
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 1 |
3 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index a140dc239c..48437a1c9e 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -147,9 +147,9 @@ module ActiveRecord scope.includes! item.includes_values end + scope.unscope!(*item.unscope_values) scope.where_clause += item.where_clause scope.order_values |= item.order_values - scope.unscope!(*item.unscope_values) end reflection = reflection.next diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index cd19a7a5bc..4ecf53e6d1 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -2358,4 +2358,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal [bulb.id], car.bulb_ids assert_no_queries { car.bulb_ids } end + + def test_has_many_association_with_rewhere + assert_equal 'Don\'t think too hard', posts(:welcome).comments_with_rewhere.first.body + end end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 81a18188d4..45a379df98 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -67,6 +67,7 @@ class Post < ActiveRecord::Base end has_many :comments_with_extend_2, extend: [NamedExtension, NamedExtension2], class_name: "Comment", foreign_key: "post_id" + has_many :comments_with_rewhere, -> { rewhere(post_id: 2) }, class_name: "Comment" has_many :author_favorites, :through => :author has_many :author_categorizations, :through => :author, :source => :categorizations |