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

Recursively embeds many problem

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

      Hello,
      I have a problem with more than 4-level trees. I try to create 1.1.1.1.1 and 1.1.1.2.1 into 1.1.1.1 and 1.1.1.2, but gem creates both entries into 1.1.1.1.

      Model (as documentation http://mongoid.org/en/mongoid/v3/relations.html)

      class Tag
        include Mongoid::Document
        recursively_embeds_many
        field :name, type: String
      end
      

      Rails console commands

      >> parent = Tag.new(name: '1')
      #<Tag _id: 54cf7e29766d613d590e0000, name: "1">
      
      >> parent.save
      true
      
      >> child = parent.child_tags.build
      #<Tag _id: 54cf7e4d766d613d590f0000, name: nil>
      
      >> child.name='1.1'
      "1.1"
      
      >> child.save
      true
      
      >> child = parent.child_tags.first.child_tags.build
      #<Tag _id: 54cf7e6b766d613d59100000, name: nil>
      
      >> child.name='1.1.1'
      "1.1.1"
      
      >> child.save
      true
      
      >> child = parent.child_tags.first.child_tags.first.child_tags.build
      #<Tag _id: 54cf7e83766d613d59110000, name: nil>
      
      >> child.name = '1.1.1.1'
      "1.1.1.1"
      
      >> child.save
      true
      
      >> child = parent.child_tags.first.child_tags.first.child_tags.build
      #<Tag _id: 54cf7e98766d613d59120000, name: nil>
      
      >> child.name = '1.1.1.2'
      "1.1.1.2"
      
      >> child.save
      true
      
      >> child = parent.child_tags.first.child_tags.first.child_tags.first.child_tags.build
      #<Tag _id: 54cf7ec9766d613d59130000, name: nil>
      
      >> child.name='1.1.1.1.1'
      "1.1.1.1.1"
      
      >> child.save
      true
      
      >> child = parent.child_tags.first.child_tags.first.child_tags.last.child_tags.build
      #<Tag _id: 54cf7eea766d613d59140000, name: nil>
      
      >> child.name='1.1.1.2.1'
      "1.1.1.2.1"
      
      >> child.save
      true
      

      Result

      Rails 4.1.8, Ruby 2.1.2, mongoid 4.0.0

            Assignee:
            Unassigned Unassigned
            Reporter:
            vmamaev Vadim Mamaev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: