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

A duplicated item is created

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: None
    • Fix Version/s: 5.0.2
    • Component/s: None
    • Labels:

      Description

      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).

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: