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

Dynamic collection name incorrectly writes when using validates_uniqueness_of

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

      class SomeModel
        include Mongoid::Document    
      
        field :somefield
      
        validates_uniqueness_of :somefield
      end
      
      SomeModel.with(collection: 'new_name').create({ 'key' => 'val' }) 
      

      When dynamically setting the collection name using with if theres a call to validates_uniqueness_of the record will automatically be written to the "some_model" collection instead of the "new_name" collection. No error or warning is thrown. This does not seem like the desired behavior. Is there another way to handle uniqueness of fields in dynamic collection names?

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

              Created:
              Updated:
              Resolved: