File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,10 @@ module Config
72
72
# to assign an incompatible type to a field.
73
73
option :strict_type_assignment , default : false
74
74
75
+ # Indicates whether uncastable values from the database should
76
+ # be returned wrapped by Mongoid::RawValue class.
77
+ option :wrap_uncastable_values_from_database , default : false
78
+
75
79
# Use ActiveSupport's time zone in time operations instead of the
76
80
# Ruby default time zone.
77
81
option :use_activesupport_time_zone , default : true
Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ class Standard
9
9
# Set readers for the instance variables.
10
10
attr_accessor :default_val , :label , :name , :options
11
11
12
+ # If type.mongoize returns Mongoid::RawValue,
13
+ # handle according to field or global strict setting
12
14
def mongoize ( object )
13
15
value = type . mongoize ( object )
14
- unless value . is_a? ( Mongoid ::RawValue )
16
+ if value . is_a? ( Mongoid ::RawValue )
15
17
case strict
16
18
when :error then value . raise_error!
17
19
when :warn then value . warn
@@ -20,7 +22,17 @@ def mongoize(object)
20
22
value
21
23
end
22
24
23
- def_delegators :type , :demongoize , :evolve
25
+ # If type.demongoize returns Mongoid::RawValue,
26
+ # return the inner value according to Mongoid.wrap_uncastable_values_from_database
27
+ def demongoize ( object )
28
+ value = type . demongoize ( object )
29
+ if value . is_a? ( Mongoid ::RawValue ) && !Mongoid . wrap_uncastable_values_from_database
30
+ return value . raw_value
31
+ end
32
+ value
33
+ end
34
+
35
+ def_delegators :type , :evolve
24
36
25
37
# Adds the atomic changes for this type of resizable field.
26
38
#
You can’t perform that action at this time.
0 commit comments