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

A duplicated item is created

    • Type: Icon: Task Task
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.2
    • Affects Version/s: None
    • Component/s: None

      Hi,
      I get a weird situation after one of my callbacks is called.
      I got a class:

      class InfoPacket < MongoModels::MongoInfoModel
        include Mongoid::Document
        include Mongoid::Attributes::Dynamic
      
        # relations 
        embedded_in :info_item
        accepts_nested_attributes_for :info_item
        
        # attributes
        field :index, type: Integer
        field :insertion_time, type: DateTime
        alias_attribute :packet_index, :index
      
        #indexes
        index({ index: 1, insertion_time: 1 }, { unique: true })
        
        # validations
        validates_presence_of :index
      
        # callbacks
        before_create :find_info_item
      
        def find_info_item
          self.info_item = InfoItem.where(sha1: self.info_item.sha1).first || self.info_item
        end
      end
      

      When I create a new "InfoPacket" which belongs to a new "InfoItem" I get the InfoPacket created twice!
      That means I'll see in my mongo DB a InfoItem record with an array of 2 InfoPackets that has the same values (even the "_id' is identical).

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

              Created:
              Updated:
              Resolved: