Skip to content

Commit 28a7dad

Browse files
committed
MONGOID-5222 add note to custom types section
1 parent f472402 commit 28a7dad

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/reference/fields.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,14 @@ setter methods for fields of your custom type.
10071007
venue = Venue.new(location: point) # This uses the Point#mongoize instance method.
10081008
venue = Venue.new(location: [ 12, 24 ]) # This uses the Point.mongoize class method.
10091009

1010+
.. note::
1011+
1012+
The ``mongoize`` method should raise an "InvalidValue" error on values that
1013+
are uncastable to your custom type. Mongoid will handle catching that error
1014+
and writing ``nil`` if the ``validate_attribute_types`` flag is turned off.
1015+
See the secion on :ref:`Uncastable Values <uncastable-values>` for more
1016+
details.
1017+
10101018
The class method ``demongoize`` does the inverse of ``mongoize``. It takes the raw object
10111019
from the MongoDB Ruby driver and converts it to an instance of your custom type.
10121020
In this case, the database driver returns an ``Array`` and we instantiate a ``Point`` from it.

0 commit comments

Comments
 (0)