diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-04 02:47:05 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-04 02:47:05 +0900 |
commit | 5ccf53056a44eda7379a2e74f88079582419c8e7 (patch) | |
tree | 520ab5bad11c4ba874ac6bf8518a10aaed56a7e7 | |
parent | ef25fbfc713d3dea833952599c921a389df0afa7 (diff) | |
parent | 82b0ff03b1d97c29472a65ef15103932d15ff75e (diff) | |
download | rails-5ccf53056a44eda7379a2e74f88079582419c8e7.tar.gz rails-5ccf53056a44eda7379a2e74f88079582419c8e7.tar.bz2 rails-5ccf53056a44eda7379a2e74f88079582419c8e7.zip |
Merge pull request #35460 from abhaynikam/33611-follow-up-on-add-reselect
Fixed reselect throwing NoMethodError on ActiveRecord.
-rw-r--r-- | activerecord/lib/active_record/querying.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/relation/delegation_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation/select_test.rb | 7 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 6 |
4 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/querying.rb b/activerecord/lib/active_record/querying.rb index b3eeb60571..79af51bdba 100644 --- a/activerecord/lib/active_record/querying.rb +++ b/activerecord/lib/active_record/querying.rb @@ -11,7 +11,8 @@ module ActiveRecord delegate :find_each, :find_in_batches, :in_batches, to: :all delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins, :left_joins, :left_outer_joins, :or, :where, :rewhere, :preload, :eager_load, :includes, :from, :lock, :readonly, :extending, - :having, :create_with, :distinct, :references, :none, :unscope, :merge, to: :all + :having, :create_with, :distinct, :references, :none, :unscope, :merge, + :reselect, to: :all delegate :count, :average, :minimum, :maximum, :sum, :calculate, to: :all delegate :pluck, :pick, :ids, to: :all diff --git a/activerecord/test/cases/relation/delegation_test.rb b/activerecord/test/cases/relation/delegation_test.rb index 4de3b1300c..31e7a4b8f4 100644 --- a/activerecord/test/cases/relation/delegation_test.rb +++ b/activerecord/test/cases/relation/delegation_test.rb @@ -56,7 +56,7 @@ module ActiveRecord :where, :rewhere, :preload, :eager_load, :includes, :from, :lock, :readonly, :extending, :having, :create_with, :distinct, :references, :none, :unscope, :merge, :count, :average, :minimum, :maximum, :sum, :calculate, - :pluck, :pick, :ids, + :pluck, :pick, :ids, :reselect, ] def test_delegate_querying_methods diff --git a/activerecord/test/cases/relation/select_test.rb b/activerecord/test/cases/relation/select_test.rb index 32e8f473ff..586aaadd0a 100644 --- a/activerecord/test/cases/relation/select_test.rb +++ b/activerecord/test/cases/relation/select_test.rb @@ -16,5 +16,12 @@ module ActiveRecord expected = Post.select(:title).to_sql assert_equal expected, Post.select(:title, :body).reselect(:title).to_sql end + + def test_reselect_with_default_scope_select + expected = Post.select(:title).to_sql + actual = PostWithDefaultSelect.reselect(:title).to_sql + + assert_equal expected, actual + end end end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 53cbda83ed..61e5f14100 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -212,6 +212,12 @@ class FirstPost < ActiveRecord::Base has_one :comment, foreign_key: :post_id end +class PostWithDefaultSelect < ActiveRecord::Base + self.table_name = "posts" + + default_scope { select(:author_id) } +end + class TaggedPost < Post has_many :taggings, -> { rewhere(taggable_type: "TaggedPost") }, as: :taggable has_many :tags, through: :taggings |