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

validates_uniqueness does not work for embedded models?

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

      validates_uniqueness does not work when it's set in an embedded document. Let's say I want all report names to be unique (system-wide):

      class User
      embeds_one :report
      end

      class Report
      field :name
      validates_uniqueness_of :name
      embedded_in :user, :inverse_of => :report
      end

      With the following spec:

      report = Report.make(:name => "x")
      Report.make_unsaved(:name => "x").should_not be_valid # Error, it is valid!

      I'm not sure this is a bug, it might very well be I'm doing something wrong here. But, maybe it is a bug.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ariejan Ariejan de Vroom
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: