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

uniqueness of scope is not working for deleted documents in mongoid 2.4.11

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

      class Folder
        include Mongoid::Document
        include Mongoid::Paranoia
        field :name, :type => String
        has_many :folder_items
      end
      
      class FolderItem
        include Mongoid::Document
        include Mongoid::Paranoia
        belongs_to :folder
        field :name, :type => String
        validates :name, :uniqueness => {:scope => :folder_id, :message => 'buyaaa', :case_sensitive => false} 
      end
      
      fun = Folder.create(:name => 'Entertainment')
      work = Folder.create(:name => 'Work')
      music = FolderItem.create(:name => 'Music', :folder_id => fun.id)
      movie = FolderItem.new(:name => 'Movies', :folder_id => fun.id)
      movie.valid?
      movie.save
      movie.delete
      movie = FolderItem.new(:name => 'Movies', :folder_id => fun.id)
      
      movie.valid?
      # MONGODB (0ms) cloudfactory_development['$cmd'].find({"count"=>"folder_items", "query"=>{:name=>"Movies", :folder_id=>BSON::ObjectId('4feafbaa6f90cb295200001e')}, "fields"=>nil}).limit(-1)
      => false
      

      As you can see, there's no deleted query (as it should be accompanied with Paranoia) fired along the last line and we can't create movie once it's deleted in the same folder.

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

              Created:
              Updated:
              Resolved: