Skip to content

Commit 7e869d0

Browse files
committed
MONGOID-5222 answer comments
1 parent d9dc0fc commit 7e869d0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

docs/reference/fields.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ Assigning Uncastable Values
834834

835835
In Mongoid 8, Mongoid has standardized the treatment of the assignment of
836836
"uncastable" values. A value is considered "uncastable" when it cannot be
837-
coerced to the type of the assigning field. For example:
837+
coerced to the type of the field. For example:
838838

839839
.. code::
840840

@@ -1010,7 +1010,7 @@ setter methods for fields of your custom type.
10101010
.. note::
10111011

10121012
The ``mongoize`` method should raise a ``Mongoid::Errors::InvalidValue`` on values that
1013-
are uncastable to your custom type. Mongoid will handle catching that error
1013+
are uncastable to your custom type. Mongoid will handle rescuing that error
10141014
and writing ``nil`` if the ``validate_attribute_types`` flag is turned off.
10151015
See the secion on :ref:`Uncastable Values <uncastable-values>` for more
10161016
details.

lib/mongoid/attributes.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ def write_attribute(name, value)
176176
typed_value = if Mongoid.validate_attribute_types
177177
typed_value_for(field_name, value)
178178
else
179-
typed_value_for(field_name, value) rescue nil
179+
begin
180+
typed_value_for(field_name, value)
181+
rescue Errors::InvalidValue
182+
nil
183+
end
180184
end
181185

182186
unless attributes[field_name] == typed_value || attribute_changed?(field_name)

0 commit comments

Comments
 (0)