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

validates_uniqueness does not work for embedded models?

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:
      None

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: