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

Saving embedded grandchildren creates additional embedded documents

    • Type: Icon: Task Task
    • Resolution: Done
    • 5.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      I ran into an issue where I have a model that embeds_many of another model, that has it's own embeds_many.

      For example:

      parent: 
        - child_1:
        - child_2:
          - grandchild
      

      The issue comes up when you update one of the grandchildren. It saves the grandchild just fine but also creates a additional grandchild record. The number of records that get created is directly tied to how many children there are. Three children will create three grandchild records. If there is only one child record, there is no problem.

      I created a repo with specs do demonstrate this: https://github.com/adamcrown/grandchild-save-bug

      The best workaround I've found is to call save on the child instead of the grandchild.

      For some reason I can't get Travis CI to reproduce the bug, but I've reproduced it on multiple computers. Please clone the repo and let me know if it passes for you. There should be one failed and one passed spec.

            Assignee:
            Unassigned Unassigned
            Reporter:
            adamcrown adamcrown
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: