Skip to content

Commit d73d3cd

Browse files
authored
Merge pull request rails#46253 from sampatbadhe/extend_reselect_with_hashes
Allow ActiveRecord::QueryMethods#reselect to accept a hash
2 parents d1aa6af + 90e96e5 commit d73d3cd

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Allow ActiveRecord::QueryMethods#reselect to receive hash values, similar to ActiveRecord::QueryMethods#select
2+
3+
*Sampat Badhe*
4+
15
* Validate options when managing columns and tables in migrations.
26

37
If an invalid option is passed to a migration method like `create_table` and `add_column`, an error will be raised

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ def with!(*args) # :nodoc:
406406
# Note that we're unscoping the entire select statement.
407407
def reselect(*args)
408408
check_if_method_has_arguments!(__callee__, args)
409+
args = process_select_args(args)
409410
spawn.reselect!(*args)
410411
end
411412

activerecord/test/cases/relation/select_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ def test_reselect_with_default_scope_select
8080
assert_equal expected, actual
8181
end
8282

83+
def test_reselect_with_hash_argument
84+
expected = Post.select(:title, posts: { title: :post_title }).to_sql
85+
actual = Post.select(:title, :body).reselect(:title, posts: { title: :post_title }).to_sql
86+
assert_equal expected, actual
87+
end
88+
89+
def test_reselect_with_one_level_hash_argument
90+
expected = Post.select(:title, title: :post_title).to_sql
91+
actual = Post.select(:title, :body).reselect(:title, title: :post_title).to_sql
92+
assert_equal expected, actual
93+
end
94+
8395
def test_non_select_columns_wont_be_loaded
8496
posts = Post.select("UPPER(title) AS title")
8597

0 commit comments

Comments
 (0)