Skip to content

Commit 16b5d6d

Browse files
authored
MONGOID-4949 update inheritance documentation to include note about bogus discriminator values (#4848)
* MONGOID-4949 add special note syntax * MONGOID-4949 language change * MONGOID-4949 add to the note * MONGOID-4949 add language about no discriminator value * MONGOID-4949 change language in note
1 parent 8f42990 commit 16b5d6d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

source/tutorials/mongoid-documents.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,17 @@ collection. An additional attribute ``_type`` is stored in order to make sure wh
11581158
from the database the correct document is returned. This also holds true for the embedded
11591159
documents ``Circle``, ``Rectangle``, and ``Shape``.
11601160

1161+
.. note::
1162+
1163+
When searching for a ``Circle``, the query will only return documents in the shape collection
1164+
where the ``_type`` (or whatever the discriminator key was set to) field has the value ``Circle`` (or
1165+
whatever the discriminator value was set to), all other discriminator values will be considered an object
1166+
of the Shape class.
1167+
1168+
Similarly, when querying by parent classes (``Canvas`` in this example), any documents in the collection
1169+
that do not have a discriminator value, or whose discriminator value does not map to either the parent
1170+
or any of its descendants, will be returned as instances of the parent class.
1171+
11611172
Changing the Discriminator Key
11621173
------------------------------
11631174
Mongoid supports changing the discriminator key from the default ``_type``. There are a few
@@ -1290,10 +1301,6 @@ Here, a call to the ``discriminator_value=`` setter was added to ``Circle``.
12901301
Now, on creation of a ``Circle``, the document will contain a field with the key ``_type`` (or whatever the ``discriminator_key`` was changed to)
12911302
and the value "round thing."
12921303

1293-
Note that after changing the discriminator value, when searching for a ``Circle``, the query will only return documents in the shape collection
1294-
with the discriminator field having the value "round thing." All other discriminator values (even ``Circle``) that already exist in the database
1295-
will be considered an object of the ``Shape`` class.
1296-
12971304
Querying Subclasses
12981305
-------------------
12991306

0 commit comments

Comments
 (0)