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

validates_uniqueness_of Array field should have order_insensitive option

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      validates_uniqueness_of for a String field has case_insensitive option.

      By analogy, validates_uniqueness_of for an Array field should have order_insensitive option.

      This can be done using this:

      validate_uniqueness_of :my_array_field
      
      #=>
      # values = my_array_field.uniq
      # Klass.where(my_array_field: { "$size" => values.size, "$all" => values }).ne(_id: self._id).exists?
      

      This is not a critical issue but I came across this while coding and thought it would make sense to add.

            Assignee:
            Unassigned Unassigned
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: