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

has_one referencing undefined class passes validation when validating a new model instance

      The behavior between a has_one and has_many association differs if an association class is missing (i.e. if `Widget` is not defined):

      Has One:

      class User
        include Mongoid::Document
        has_one :widget
      end
      
      User.new.valid? # true
      

      Has Many:

      class User
        include Mongoid::Document
        has_many :widgets
      end
      
      User.new.valid? # raises NameError (uninitialized constant Widget)
      

      This only impacts new records. For example:

      User.create
      User.last.valid? # correctly raises an exception
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            ksylvest Kevin Sylvestre
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: