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

default_scope should not have bearing on uniqueness validation

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

      All,

      At present, I believe having a default_scope on a model will interfere with the uniqueness validation. If you add a default scope to the spec model located at spec/app/models/dictionary.rb such that it becomes:

      class Dictionary
        include Mongoid::Document
        field :name, type: String
        field :publisher, type: String
        field :year, type: Integer
        field :published, type: Time
        has_many :words, validate: false
        default_scope where(published: 1999)
      end
      

      ... then a large chunk of tests will fail. A further example is explained in this gist.
      I do not have time at the moment to implement a patch, but will try to do so if someone else doesn't beat me to it. I bet it's a matter of making sure unscoped is used during the validation.

      Thanks!

            Assignee:
            Unassigned Unassigned
            Reporter:
            astjohn Adam St. John
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: