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

'set' in 'recursively_embeds_many' on lower levels persists incorrectly as a separate hash

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

      Hello,
      this code should set

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      :nameCopy

      {{ to be the same as

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      :name

      }}:

      Unable to find source-code formatter for language: `ruby. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class Node
          include Mongoid::Document
      
          field :name, type: String
          field :nameCopy, type: String
          recursively_embeds_many
      
          def walk
              set(nameCopy: name)
              child_nodes.each { |node| node.walk }
          end
          
      end
      
      root = Node.new(name: "root")
      child1A = Node.new(name: "child1A")
      child1B = Node.new(name: "child1B")
      child2A = Node.new(name: "child2A")
      
      root.child_nodes.push child1A
      root.child_nodes.push child1B
      
      child1B.child_nodes.push child2A
      
      root.walk
      root.save!
      

      `
      Everything works as expected. But the order is switch:

      Unable to find source-code formatter for language: `ruby. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      root.save!
      root.walk
      

      `
      then the node child2A doesn't have

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      :nodeCopy

      ` set. Instead, it is added on a higher level as a separate hash.

      Unable to find source-code formatter for language: `json. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      {
        "_id": ObjectId("552138834d616336c8000000"),
        "name": "root",
        "child_nodes": [
          {
            "_id": ObjectId("552138834d616336c8010000"),
            "name": "child1A",
            "nameCopy": "child1A"
          },
          {
            "_id": ObjectId("552138834d616336c8020000"),
            "name": "child1B",
            "child_nodes": [
              {
                "_id": ObjectId("552138834d616336c8030000"),
                "name": "child2A"
              },
              {
                "nameCopy": "child2A"     <--- this should be part of ObjectId("552138834d616336c8030000")
              }
            ],
            "nameCopy": "child1B"
          }
        ],
        "nameCopy": "root"
      }
      

      `
      I am new to mongoid. Did I miss anything or is it a bug?
      Here is the database log:

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      INSERT       database=meteor collection=nodes documents=[
      {
        "_id"=>BSON: : ObjectId('552138834d616336c8000000'),
        "name"=>"root",
        "child_nodes"=>[
          {
            "_id"=>BSON: : ObjectId('552138834d616336c8010000'),
            "name"=>"child1A"
          },
          {
            "_id"=>BSON: : ObjectId('552138834d616336c8020000'),
            "name"=>"child1B",
            "child_nodes"=>[
              {
                "_id"=>BSON: : ObjectId('552138834d616336c8030000'),
                "name"=>"child2A"
              }
            ]
          }
        ]
      }
      ] flags=[]
      
      database=meteor collection=nodes selector={"_id"=>BSON::ObjectId('552138834d616336c8000000')} update={"$set"=>{"nameCopy"=>"root"}} flags=[]
      
      database=meteor collection=nodes selector={"_id"=>BSON::ObjectId('552138834d616336c8000000'), "child_nodes._id"=>BSON::ObjectId('552138834d616336c8010000')} update={"$set"=>{"child_nodes.$.nameCopy"=>"child1A"}} flags=[]
      
      database=meteor collection=nodes selector={"_id"=>BSON::ObjectId('552138834d616336c8000000'), "child_nodes._id"=>BSON::ObjectId('552138834d616336c8020000')} update={"$set"=>{"child_nodes.$.nameCopy"=>"child1B"}} flags=[]
      
      database=meteor collection=nodes selector={"_id"=>BSON::ObjectId('552138834d616336c8000000'), "child_nodes._id"=>BSON::ObjectId('552138834d616336c8020000'), "child_nodes.1.child_nodes._id"=>BSON::ObjectId('552138834d616336c8030000')} update={"$set"=>{"child_nodes.1.child_nodes.$.nameCopy"=>"child2A"}} flags=[]
      

      `
      Thanks,
      Michal

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

              Created:
              Updated:
              Resolved: