@@ -108,7 +108,7 @@ type. Such fields are untyped:
108
108
109
109
class Product
110
110
include Mongoid::Document
111
-
111
+
112
112
field :properties
113
113
# Equivalent to:
114
114
field :properties, type: Object
@@ -124,7 +124,7 @@ ahead of time:
124
124
product = Product.new(properties: "color=white,size=large")
125
125
product.properties
126
126
# => "color=white,size=large"
127
-
127
+
128
128
product = Product.new(properties: {color: "white", size: "large"})
129
129
product.properties
130
130
# => {:color=>"white", :size=>"large"}
@@ -914,6 +914,15 @@ Note that the original uncastable values will be stored in the
914
914
user.attributes_before_type_cast["name"]
915
915
# => ["Mike", "Trout"]
916
916
917
+ .. note::
918
+
919
+ Note that for numeric fields, any class that defines ``to_i`` for Integer
920
+ fields, ``to_f`` for Floats, and ``to_d`` for BigDecimals, is castable.
921
+ Strings are the exception and will only call the corresponding ``to_*``
922
+ method if the string is numeric. If a class only defines ``to_i`` and not
923
+ ``to_f`` and is being assigned to a Float field, this is uncastable, and Mongoid
924
+ will not perform a two-step conversion (i.e. ``to_i`` and then ``to_f``).
925
+
917
926
918
927
Reading Uncastable Values
919
928
`````````````````````````
0 commit comments