Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4482

Unscoped includes

    • Type: Icon: Task Task
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 5.0.2
    • Component/s: Query
    • Labels:
      None
    • 2

      Hi

      I do soft-delete for some Mongoid models:

      class Comment
        include Mongoid::Document
        
        belongs_to :author
      end
      
      class Author
        include Mongoid::Document
        
        has_many :comments
        
        default_scope -> { where(deleted_at: nil) }
      end
      

      For avoiding N+1 while listings comments and authors, I would like to `Comments.includes(:author)`, but I do want to include deleted authors for that querying, meaning that I want to skip the `default_scope` in the `Author`'s model.

      Is it possible?

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            phstc Pablo Cantero
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: