Skip to content

Commit 8271186

Browse files
committed
Merge pull request rails#48095 from ippachi/triple-dot-range-unscope
Fix unscope not working when where by tripe dot range
2 parents 2537902 + ed68048 commit 8271186

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

activerecord/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
* Fix unscope is not working in specific case
2+
3+
Before:
4+
```ruby
5+
Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts` WHERE `posts`.`id` >= 1 AND `posts`.`id` < 3"
6+
7+
```
8+
9+
After:
10+
```ruby
11+
Post.where(id: 1...3).unscope(where: :id).to_sql # "SELECT `posts`.* FROM `posts`"
12+
```
13+
14+
Fixes #48094.
15+
16+
*Kazuya Hatanaka*
17+
118
* Change `has_secure_token` default to `on: :initialize`
219

320
Change the new default value from `on: :create` to `on: :initialize`

activerecord/lib/arel/nodes/and.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def right
1818
children[1]
1919
end
2020

21+
def fetch_attribute(&block)
22+
children.any? && children.all? { |child| child.fetch_attribute(&block) }
23+
end
24+
2125
def hash
2226
children.hash
2327
end

activerecord/test/cases/relations_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,20 @@ def test_unscope_grouped_where
23292329
assert_equal Post.count, posts.unscope(where: :title).count
23302330
end
23312331

2332+
def test_unscope_with_double_dot_where
2333+
posts = Post.where(id: 1..2)
2334+
2335+
assert_equal 2, posts.count
2336+
assert_equal Post.count, posts.unscope(where: :id).count
2337+
end
2338+
2339+
def test_unscope_with_triple_dot_where
2340+
posts = Post.where(id: 1...3)
2341+
2342+
assert_equal 2, posts.count
2343+
assert_equal Post.count, posts.unscope(where: :id).count
2344+
end
2345+
23322346
def test_locked_should_not_build_arel
23332347
posts = Post.locked
23342348
assert_predicate posts, :locked?

0 commit comments

Comments
 (0)