default_scope and associations

前端 未结 6 1582
猫巷女王i
猫巷女王i 2020-12-06 04:17

Suppose I have a Post model, and a Comment model. Using a common pattern, Post has_many Comments.

If Comment has a default_scope set:

default_scope w         


        
6条回答
  •  醉酒成梦
    2020-12-06 05:02

    Rails 4.1.1

    Comment.unscope(where: :deleted_at) { Post.first.comments }
    

    Or

    Comment.unscoped { Post.first.comments.scope }
    

    Note that I added .scope, it seems like this block should return kind of ActiveRecord_AssociationRelation (what .scope does) not ActiveRecord_Associations_CollectionProxy (without a .scope)

提交回复
热议问题