mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #9889 from neerajdotname/unscoped
Unscoped works with other named scope even without block form
This commit is contained in:
commit
bad0b81a07
2 changed files with 4 additions and 8 deletions
|
@ -27,14 +27,6 @@ module ActiveRecord
|
|||
# Post.unscoped {
|
||||
# Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10"
|
||||
# }
|
||||
#
|
||||
# It is recommended that you use the block form of unscoped because
|
||||
# chaining unscoped with +scope+ does not work. Assuming that
|
||||
# +published+ is a +scope+, the following two statements
|
||||
# are equal: the +default_scope+ is applied on both.
|
||||
#
|
||||
# Post.unscoped.published
|
||||
# Post.published
|
||||
def unscoped
|
||||
block_given? ? relation.scoping { yield } : relation
|
||||
end
|
||||
|
|
|
@ -634,7 +634,11 @@ class DefaultScopingTest < ActiveRecord::TestCase
|
|||
assert_equal [DeveloperCalledJamis.find(developers(:poor_jamis).id)], DeveloperCalledJamis.poor
|
||||
|
||||
assert DeveloperCalledJamis.unscoped.poor.include?(developers(:david).becomes(DeveloperCalledJamis))
|
||||
|
||||
assert_equal 11, DeveloperCalledJamis.unscoped.length
|
||||
assert_equal 1, DeveloperCalledJamis.poor.length
|
||||
assert_equal 10, DeveloperCalledJamis.unscoped.poor.length
|
||||
assert_equal 10, DeveloperCalledJamis.unscoped { DeveloperCalledJamis.poor }.length
|
||||
end
|
||||
|
||||
def test_default_scope_select_ignored_by_aggregations
|
||||
|
|
Loading…
Reference in a new issue