-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Minor Change
-
None
-
None
-
None
-
None
-
None
-
None
Our usage of ActiveModel::MissingAttribute is quite different than ActiveRecord's usage/intention.
Mongoid raises ActiveModel::MissingAttribute when using the .only projection method, like so:
Band.only(:name).first.label
However, Rails raises this error when attempting to call a getter which is not defined. From the Rails docs:
# Raised when an attribute is not defined.
#
# class User < ActiveRecord::Base
# has_many :pets
# end
#
# user = User.first
# user.pets.select(:id).first.user_id
# # => ActiveModel::MissingAttributeError: missing attribute: user_id
In this same case, Mongoid would simply raise a plain-old MethodMissing error.
I propose to rename this error to Mongoid::Errors::AttributeNotLoaded to better clarify its intention. In addition, we should:
- Have this new error class inherit from Mongoid::Error::MongoidError, same as every other error in Mongoid.
- Address
MONGOID-5320(make error message more informative)
- is duplicated by
-
MONGOID-5320 Make MissingAttributeError more informative
-
- Closed
-