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

Create does a slow query on every related object

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Currently, when you do a create, it performs a query for all related (references_many) objects. This is really inefficient when those related collections are large.

      For example, if a User references_many :posts, x = User.create will call x.posts.all.each ...

      This happens in update_associations (here) where it calls:
      {{send(name).each

      { |doc| doc.save }

      if new_record?}}

      I believe that code is incorrect, and should say unless new_record? instead. Although, I'm not sure why you need to loop through every related object anyway.

            Assignee:
            Unassigned Unassigned
            Reporter:
            idris Idris Mokhtarzada
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: