-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: 7.0.2
-
Component/s: Validations
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