File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
activerecord/lib/active_record/scoping Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -24,14 +24,22 @@ module ClassMethods
24
24
# Returns a scope for the model without the previously set scopes.
25
25
#
26
26
# class Post < ActiveRecord::Base
27
+ # belongs_to :user
28
+ #
27
29
# def self.default_scope
28
30
# where(published: true)
29
31
# end
30
32
# end
31
33
#
34
+ # class User < ActiveRecord::Base
35
+ # has_many :posts
36
+ # end
37
+ #
32
38
# Post.all # Fires "SELECT * FROM posts WHERE published = true"
33
39
# Post.unscoped.all # Fires "SELECT * FROM posts"
34
40
# 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"
35
43
#
36
44
# This method also accepts a block. All queries inside the block will
37
45
# not use the previously set scopes.
You can’t perform that action at this time.
0 commit comments