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

Uniqueness validation doesn't work with inheritance

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

      When Bar inherits Foo, uniqueness validation which is defined in Foo should work for Bar. But it doesn't work since 3.0.20.

      require 'mongoid'
      #=> false
      class Foo
        include Mongoid::Document
        field :name, type: String
        validates :name, uniqueness: true
      end
      #=> {:uniqueness=>true}
       
      class Bar < Foo
      end
      #=> nil
       
      Foo.create!(name: "server1")
      #=> #<Foo _id: 51109c8d5427dbe7e2000001, _type: nil, name: "server1">
      bar = Bar.new(name: "server1")
      #=> #<Bar _id: 51109c8d5427dbe7e2000002, _type: "Bar", name: "server1">
      bar.valid?
      #=> true
      

      bar.valid? should return false but returns true.

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

              Created:
              Updated:
              Resolved: