Skip to content

Commit 485ec2a

Browse files
authored
Merge pull request rails#45770 from RyanMacG/update-docs-for-unscoped
Update docs for `.unscoped` to be explicit about associations
2 parents 781a722 + 0a7a524 commit 485ec2a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

activerecord/lib/active_record/scoping/default.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@ module ClassMethods
2424
# Returns a scope for the model without the previously set scopes.
2525
#
2626
# class Post < ActiveRecord::Base
27+
# belongs_to :user
28+
#
2729
# def self.default_scope
2830
# where(published: true)
2931
# end
3032
# end
3133
#
34+
# class User < ActiveRecord::Base
35+
# has_many :posts
36+
# end
37+
#
3238
# Post.all # Fires "SELECT * FROM posts WHERE published = true"
3339
# Post.unscoped.all # Fires "SELECT * FROM posts"
3440
# Post.where(published: false).unscoped.all # Fires "SELECT * FROM posts"
41+
# User.find(1).posts # Fires "SELECT * FROM posts WHERE published = true AND posts.user_id = 1"
42+
# User.find(1).posts.unscoped # Fires "SELECT * FROM posts"
3543
#
3644
# This method also accepts a block. All queries inside the block will
3745
# not use the previously set scopes.

0 commit comments

Comments
 (0)