Unscoped includes

XMLWordPrintableJSON

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

      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 (Inactive)
              Reporter:
              Pablo Cantero
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: