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

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

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.0
    • Affects Version/s: 5.2.1
    • Component/s: 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 Emily Stolfo
            Reporter:
            halloffame Ryan Hall
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: