An instance of Mongoid::Document should auto includes itself in a has_many query

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Duplicate
    • Priority: Major - P3
    • 7.0.0
    • Affects Version/s: 5.2.1
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Given two classes:

      class User
        include Mongoid::Document
        has_many :tasks, dependent: :destroy
      end
      
      class Task
        include Mongoid::Document
        belongs_to :user
      end
      

      Is it possible for an instance of User to auto include itself on each of it's tasks?

      user.tasks.map { |t| t.user }
      

      The above example will cause n+1 queries, where n is the number of tasks. Is it possible to just automatically assign user to each task so it doesn't have to do a new lookup each time?

              Assignee:
              Emily Stolfo (Inactive)
              Reporter:
              Ryan Hall
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: