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

strange behavior on multiple nesting

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

      I have document that has embedded document wich may embed itself .

      Main model:

      class FrameType
        include Mongoid::Document
        include Mongoid::Timestamps
        
        field :name, :type => String
        field :key, :type => String
        
        embeds_many :slot_definitions, :as => :slot_definition_container
        
        accepts_nested_attributes_for :slot_definitions, :allow_destroy => true
          
      end
      

      Nested model:

      class SlotDefinition
        include Mongoid::Document
        
        field :name, :type => String
        field :key, :type => String
        
        embedded_in :slot_definition_container, :polymorphic => true
      end
      

      Class that inherits SlotDefinition model:

      class SlotDefinitionArray < SlotDefinition
        embeds_one :slot_definition, :as => :slot_definition_container
        
        accepts_nested_attributes_for :slot_definition
      end
      

      `

      I'm trying to update Frame and put there SlotDefinition with embedded slot definition:

      frame_type.update_attributes({"name"=>"3D Object", "key"=>"object","slot_definitions_attributes"=>{"0"=>

      {"_type"=>"SlotDefinitionFile", "name"=>"model", "key"=>"model", "file_type"=>"model", "_destroy"=>"false", "id"=>"4e65f521cf6c124af600002b"}

      , "1315315562427"=>{"_type"=>"SlotDefinitionArray", "name"=>"Materials", "key"=>"materials", "slot_definition_attributes"=>

      {"_type"=>"SlotDefinitionFrame", "name"=>"material", "key"=>"material", "frame_type_id"=>"4e65f4eccf6c124af6000012", "_destroy"=>"false"}

      , "_destroy"=>"false"}}})

      and I see this log message in my log:

      wikimedical_development['frame_types'].update(

      {"_id"=>BSON::ObjectId('4e65f521cf6c124af600002a')}

      , {"$pushAll"=>{"slot_definitions"=>[{"_type"=>"SlotDefinitionArray", "name"=>"Materials", "key"=>"materials", "_id"=>BSON::ObjectId('4e6622c0cf6c125bef000010'), "slot_definition"=>{"_type"=>"SlotDefinitionFrame", "name"=>"material", "key"=>"material", "frame_type_id"=>"4e65f4eccf6c124af6000012", "_id"=>BSON::ObjectId('4e6622c0cf6c125bef000011')}}]}, "$set"=>{"slot_definitions.slot_definition"=>

      {"_type"=>"SlotDefinitionFrame", "name"=>"material", "key"=>"material", "frame_type_id"=>"4e65f4eccf6c124af6000012", "_id"=>BSON::ObjectId('4e6622c0cf6c125bef000011')}

      }})

      So mongoid tries to perform 2 operations in mongo for 1 update - $pushAll and $set

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

              Created:
              Updated:
              Resolved: