A duplicated item is created

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Cannot Reproduce
    • Priority: Major - P3
    • 5.0.2
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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
              Reporter:
              benams
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: