Skip to content

Commit 6c6c0a8

Browse files
MONGOID-5467 MONGOID-5320 Change usage of ActiveModel::MissingAttributeError to Mongoid::Errors:AttributeNotLoaded (#5437)
* Change usage of ActiveModel::MissingAttributeError to Mongoid::Errors::AttributeNotLoaded. * Fix specs * Improve release notes Co-authored-by: shields <[email protected]>
1 parent 20779b6 commit 6c6c0a8

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

source/reference/crud.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ Mongoid provides several ways of accessing field values.
657657
.. note::
658658

659659
All of the access methods described below raise
660-
``ActiveModel::MissingAttributeError`` when the field being accessed is
660+
``Mongoid::Errors::AttributeNotLoaded`` when the field being accessed is
661661
:ref:`projected out <projection>`, either by virtue of not being included in
662662
:ref:`only <only>` or by virtue of being included in
663663
:ref:`without <without>`. This applies to both reads and writes.

source/reference/queries.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,12 +775,12 @@ operation is sometimes called "projection".
775775
band = Band.only(:name).first
776776

777777
Attempting to reference attributes which have not been loaded results in
778-
``ActiveModel::MissingAttributeError``.
778+
``Mongoid::Errors::AttributeNotLoaded``.
779779

780780
.. code-block:: ruby
781781

782782
band.label
783-
# ActiveModel::MissingAttributeError (Missing attribute: 'label'.)
783+
#=> raises Mongoid::Errors::AttributeNotLoaded
784784

785785
Even though Mongoid currently allows writing to attributes that have not
786786
been loaded, such writes will not be persisted

source/release-notes/mongoid-9.0.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
***********
2+
Mongoid 9.0
3+
***********
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
This page describes significant changes and improvements in Mongoid 9.0.
14+
The complete list of releases is available `on GitHub
15+
<https://github.com/mongodb/mongoid/releases>`_ and `in JIRA
16+
<https://jira.mongodb.org/projects/MONGOID?selectedItem=com.atlassian.jira.jira-projects-plugin:release-page>`_;
17+
please consult GitHub releases for detailed release notes and JIRA for
18+
the complete list of issues fixed in each release, including bug fixes.
19+
20+
21+
Raise AttributeNotLoaded error when accessing fields omitted from query projection
22+
----------------------------------------------------------------------------------
23+
24+
When attempting to access a field on a model instance which was
25+
excluded with the ``.only`` or ``.without`` query projections methods
26+
when the instance was loaded, Mongoid will now raise a
27+
``Mongoid::Errors::AttributeNotLoaded`` error.
28+
29+
.. code-block:: ruby
30+
31+
Band.only(:name).first.label
32+
#=> raises Mongoid::Errors::AttributeNotLoaded
33+
34+
Band.without(:label).first.label = 'Sub Pop Records'
35+
#=> raises Mongoid::Errors::AttributeNotLoaded
36+
37+
In earlier Mongoid versions, the same conditions would raise an
38+
``ActiveModel::MissingAttributeError``. Please check your code for
39+
any Mongoid-specific usages of this class, and change them to
40+
``Mongoid::Errors::AttributeNotLoaded``. Note additionally that
41+
``AttributeNotLoaded`` inherits from ``Mongoid::Errors::MongoidError``,
42+
while ``ActiveModel::MissingAttributeError`` does not.

0 commit comments

Comments
 (0)