mongoid 2.3.5 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. data/CHANGELOG.md +34 -176
  2. data/LICENSE +1 -1
  3. data/lib/config/locales/bg.yml +6 -0
  4. data/lib/config/locales/de.yml +6 -0
  5. data/lib/config/locales/en-GB.yml +8 -0
  6. data/lib/config/locales/en.yml +8 -0
  7. data/lib/config/locales/es.yml +9 -3
  8. data/lib/config/locales/fr.yml +6 -0
  9. data/lib/config/locales/hi.yml +6 -0
  10. data/lib/config/locales/hu.yml +6 -0
  11. data/lib/config/locales/id.yml +6 -0
  12. data/lib/config/locales/it.yml +6 -0
  13. data/lib/config/locales/ja.yml +6 -0
  14. data/lib/config/locales/kr.yml +6 -0
  15. data/lib/config/locales/nl.yml +8 -0
  16. data/lib/config/locales/pl.yml +6 -0
  17. data/lib/config/locales/pt-BR.yml +6 -0
  18. data/lib/config/locales/pt.yml +8 -2
  19. data/lib/config/locales/ro.yml +6 -0
  20. data/lib/config/locales/ru.yml +6 -0
  21. data/lib/config/locales/sv.yml +6 -0
  22. data/lib/config/locales/vi.yml +14 -8
  23. data/lib/config/locales/zh-CN.yml +6 -0
  24. data/lib/mongoid/atomic.rb +62 -13
  25. data/lib/mongoid/atomic/modifiers.rb +33 -1
  26. data/lib/mongoid/attributes.rb +5 -19
  27. data/lib/mongoid/callbacks.rb +2 -1
  28. data/lib/mongoid/collection.rb +2 -2
  29. data/lib/mongoid/collections/retry.rb +18 -6
  30. data/lib/mongoid/components.rb +2 -0
  31. data/lib/mongoid/config.rb +8 -63
  32. data/lib/mongoid/config/environment.rb +41 -0
  33. data/lib/mongoid/config/options.rb +74 -0
  34. data/lib/mongoid/contexts/enumerable.rb +0 -24
  35. data/lib/mongoid/contexts/mongo.rb +33 -3
  36. data/lib/mongoid/copyable.rb +1 -1
  37. data/lib/mongoid/criteria.rb +4 -2
  38. data/lib/mongoid/criterion/inclusion.rb +1 -16
  39. data/lib/mongoid/criterion/optional.rb +37 -10
  40. data/lib/mongoid/criterion/scoping.rb +83 -0
  41. data/lib/mongoid/criterion/selector.rb +9 -6
  42. data/lib/mongoid/default_scope.rb +1 -1
  43. data/lib/mongoid/dirty.rb +163 -29
  44. data/lib/mongoid/document.rb +58 -7
  45. data/lib/mongoid/errors.rb +2 -0
  46. data/lib/mongoid/errors/no_environment.rb +19 -0
  47. data/lib/mongoid/errors/scope_overwrite.rb +21 -0
  48. data/lib/mongoid/extensions.rb +6 -0
  49. data/lib/mongoid/extensions/array/deep_copy.rb +25 -0
  50. data/lib/mongoid/extensions/hash/deep_copy.rb +25 -0
  51. data/lib/mongoid/extensions/hash/scoping.rb +1 -1
  52. data/lib/mongoid/extensions/object/deep_copy.rb +21 -0
  53. data/lib/mongoid/extensions/proc/scoping.rb +2 -2
  54. data/lib/mongoid/extensions/symbol/inflections.rb +1 -0
  55. data/lib/mongoid/fields.rb +171 -104
  56. data/lib/mongoid/fields/{serializable → internal}/array.rb +33 -1
  57. data/lib/mongoid/fields/{serializable → internal}/big_decimal.rb +16 -1
  58. data/lib/mongoid/fields/{serializable → internal}/bignum.rb +1 -1
  59. data/lib/mongoid/fields/{serializable → internal}/binary.rb +1 -1
  60. data/lib/mongoid/fields/{serializable → internal}/boolean.rb +16 -1
  61. data/lib/mongoid/fields/{serializable → internal}/date.rb +1 -1
  62. data/lib/mongoid/fields/{serializable → internal}/date_time.rb +1 -1
  63. data/lib/mongoid/fields/{serializable → internal}/fixnum.rb +1 -1
  64. data/lib/mongoid/fields/{serializable → internal}/float.rb +16 -1
  65. data/lib/mongoid/fields/internal/foreign_keys/array.rb +74 -0
  66. data/lib/mongoid/fields/{serializable → internal}/foreign_keys/object.rb +11 -2
  67. data/lib/mongoid/fields/{serializable → internal}/hash.rb +1 -1
  68. data/lib/mongoid/fields/{serializable → internal}/integer.rb +16 -1
  69. data/lib/mongoid/fields/{serializable → internal}/localized.rb +23 -2
  70. data/lib/mongoid/fields/{serializable → internal}/nil_class.rb +16 -1
  71. data/lib/mongoid/fields/{serializable → internal}/object.rb +1 -1
  72. data/lib/mongoid/fields/{serializable → internal}/object_id.rb +16 -1
  73. data/lib/mongoid/fields/{serializable → internal}/range.rb +21 -2
  74. data/lib/mongoid/fields/{serializable → internal}/set.rb +16 -1
  75. data/lib/mongoid/fields/{serializable → internal}/string.rb +16 -1
  76. data/lib/mongoid/fields/{serializable → internal}/symbol.rb +17 -1
  77. data/lib/mongoid/fields/{serializable → internal}/time.rb +1 -1
  78. data/lib/mongoid/fields/{serializable → internal}/time_with_zone.rb +1 -1
  79. data/lib/mongoid/fields/{serializable → internal}/timekeeping.rb +16 -1
  80. data/lib/mongoid/fields/mappings.rb +8 -3
  81. data/lib/mongoid/fields/serializable.rb +34 -3
  82. data/lib/mongoid/hierarchy.rb +14 -14
  83. data/lib/mongoid/identity_map.rb +3 -2
  84. data/lib/mongoid/logger.rb +1 -7
  85. data/lib/mongoid/named_scope.rb +16 -12
  86. data/lib/mongoid/observer.rb +5 -1
  87. data/lib/mongoid/paranoia.rb +1 -0
  88. data/lib/mongoid/persistence.rb +11 -4
  89. data/lib/mongoid/persistence/atomic.rb +4 -1
  90. data/lib/mongoid/persistence/atomic/add_to_set.rb +17 -1
  91. data/lib/mongoid/persistence/atomic/sets.rb +1 -1
  92. data/lib/mongoid/railties/database.rake +1 -1
  93. data/lib/mongoid/relations.rb +1 -3
  94. data/lib/mongoid/relations/auto_save.rb +1 -1
  95. data/lib/mongoid/relations/builders.rb +1 -1
  96. data/lib/mongoid/relations/builders/embedded/many.rb +2 -6
  97. data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
  98. data/lib/mongoid/relations/builders/nested_attributes/one.rb +1 -1
  99. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -1
  100. data/lib/mongoid/relations/cascading/delete.rb +1 -1
  101. data/lib/mongoid/relations/cyclic.rb +10 -6
  102. data/lib/mongoid/relations/embedded/atomic.rb +3 -3
  103. data/lib/mongoid/relations/embedded/many.rb +98 -20
  104. data/lib/mongoid/relations/macros.rb +2 -0
  105. data/lib/mongoid/relations/many.rb +13 -0
  106. data/lib/mongoid/relations/metadata.rb +3 -3
  107. data/lib/mongoid/relations/nested_builder.rb +4 -3
  108. data/lib/mongoid/relations/proxy.rb +0 -1
  109. data/lib/mongoid/relations/referenced/batch.rb +3 -2
  110. data/lib/mongoid/relations/referenced/in.rb +3 -3
  111. data/lib/mongoid/relations/referenced/many.rb +89 -10
  112. data/lib/mongoid/relations/referenced/many_to_many.rb +34 -43
  113. data/lib/mongoid/relations/referenced/one.rb +8 -4
  114. data/lib/mongoid/relations/synchronization.rb +22 -5
  115. data/lib/mongoid/threaded.rb +38 -276
  116. data/lib/mongoid/threaded/lifecycle.rb +18 -18
  117. data/lib/mongoid/timestamps/updated.rb +13 -3
  118. data/lib/mongoid/validations.rb +22 -1
  119. data/lib/mongoid/validations/presence.rb +40 -0
  120. data/lib/mongoid/validations/uniqueness.rb +14 -3
  121. data/lib/mongoid/version.rb +1 -1
  122. data/lib/mongoid/versioning.rb +6 -2
  123. data/lib/rails/mongoid.rb +7 -1
  124. metadata +64 -45
  125. data/lib/mongoid/fields/serializable/foreign_keys/array.rb +0 -42
  126. data/lib/mongoid/relations/embedded/sort.rb +0 -31
@@ -1,12 +1,44 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for array fields.
7
7
  class Array
8
8
  include Serializable
9
9
 
10
+ # Adds the atomic changes for this type of resizable field.
11
+ #
12
+ # @example Add the atomic changes.
13
+ # field.add_atomic_changes(doc, "key", {}, [], [])
14
+ #
15
+ # @param [ Document ] document The document to add to.
16
+ # @param [ String ] key The name of the field.
17
+ # @param [ Hash ] mods The current modifications.
18
+ # @param [ Array ] new The new elements to add.
19
+ # @param [ Array ] old The old elements getting removed.
20
+ #
21
+ # @since 2.4.0
22
+ def add_atomic_changes(document, key, mods, new, old)
23
+ if new.any? && old.any?
24
+ mods[key] = document.attributes[key]
25
+ elsif new.any?
26
+ document.atomic_array_pushes[key] = new
27
+ elsif old.any?
28
+ document.atomic_array_pulls[key] = old
29
+ end
30
+ end
31
+
32
+ # Array fields are resizable.
33
+ #
34
+ # @example Is this field resizable?
35
+ # field.resizable?
36
+ #
37
+ # @return [ true ] Always true.
38
+ #
39
+ # @since 2.4.0
40
+ def resizable?; true; end
41
+
10
42
  # Serialize the object from the type defined in the model to a MongoDB
11
43
  # compatible object to store.
12
44
  #
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for big decimal fields.
7
7
  class BigDecimal
@@ -22,6 +22,21 @@ module Mongoid #:nodoc:
22
22
  object ? ::BigDecimal.new(object) : object
23
23
  end
24
24
 
25
+ # Special case to serialize the object.
26
+ #
27
+ # @example Convert to a selection.
28
+ # field.selection(object)
29
+ #
30
+ # @param [ Object ] The object to convert.
31
+ #
32
+ # @return [ Object ] The converted object.
33
+ #
34
+ # @since 2.4.0
35
+ def selection(object)
36
+ return object if object.is_a?(::Hash)
37
+ serialize(object)
38
+ end
39
+
25
40
  # Serialize the object from the type defined in the model to a MongoDB
26
41
  # compatible object to store.
27
42
  #
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
  # Defines the behaviour for bignum fields.
6
6
  class Bignum < Integer
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
  # Defines the behaviour for binary fields.
6
6
  class Binary
7
7
  include Serializable
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for boolean fields.
7
7
  class Boolean
@@ -22,6 +22,21 @@ module Mongoid #:nodoc:
22
22
  0.0 => false
23
23
  }
24
24
 
25
+ # Special case to serialize the object.
26
+ #
27
+ # @example Convert to a selection.
28
+ # field.selection(object)
29
+ #
30
+ # @param [ Object ] The object to convert.
31
+ #
32
+ # @return [ Object ] The converted object.
33
+ #
34
+ # @since 2.4.0
35
+ def selection(object)
36
+ return object if object.is_a?(::Hash)
37
+ serialize(object)
38
+ end
39
+
25
40
  # Serialize the object from the type defined in the model to a MongoDB
26
41
  # compatible object to store.
27
42
  #
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for date fields.
7
7
  class Date
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for date time fields.
7
7
  class DateTime
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
  # Defines the behaviour for fixnum fields.
6
6
  class Fixnum < Integer
7
7
  end
@@ -1,12 +1,27 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for float fields.
7
7
  class Float
8
8
  include Serializable
9
9
 
10
+ # Special case to serialize the object.
11
+ #
12
+ # @example Convert to a selection.
13
+ # field.selection(object)
14
+ #
15
+ # @param [ Object ] The object to convert.
16
+ #
17
+ # @return [ Object ] The converted object.
18
+ #
19
+ # @since 2.4.0
20
+ def selection(object)
21
+ return object if object.is_a?(::Hash)
22
+ serialize(object)
23
+ end
24
+
10
25
  # Serialize the object from the type defined in the model to a MongoDB
11
26
  # compatible object to store.
12
27
  #
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Fields #:nodoc:
4
+ module Internal #:nodoc:
5
+ module ForeignKeys #:nodoc:
6
+
7
+ # Defines the behaviour for array foreign key fields.
8
+ class Array
9
+ include Serializable
10
+
11
+ # Adds the atomic changes for this type of resizable field.
12
+ #
13
+ # @example Add the atomic changes.
14
+ # field.add_atomic_changes(doc, "key", {}, [], [])
15
+ #
16
+ # @param [ Document ] document The document to add to.
17
+ # @param [ String ] key The name of the field.
18
+ # @param [ Hash ] mods The current modifications.
19
+ # @param [ Array ] new The new elements to add.
20
+ # @param [ Array ] old The old elements getting removed.
21
+ #
22
+ # @since 2.4.0
23
+ def add_atomic_changes(document, key, mods, new, old)
24
+ if new.any? && old.any?
25
+ mods[key] = document.attributes[key]
26
+ elsif new.any?
27
+ document.atomic_array_add_to_sets[key] = new
28
+ elsif old.any?
29
+ document.atomic_array_pulls[key] = old
30
+ end
31
+ end
32
+
33
+ # Is the field a BSON::ObjectId?
34
+ #
35
+ # @example Is the field a BSON::ObjectId?
36
+ # field.object_id_field?
37
+ #
38
+ # @return [ true, false ] If the field is a BSON::ObjectId.
39
+ #
40
+ # @since 2.2.0
41
+ def object_id_field?
42
+ @object_id_field ||=
43
+ metadata.polymorphic? ? true : metadata.klass.using_object_ids?
44
+ end
45
+
46
+ # Array fields are resizable.
47
+ #
48
+ # @example Is this field resizable?
49
+ # field.resizable?
50
+ #
51
+ # @return [ true ] Always true.
52
+ #
53
+ # @since 2.4.0
54
+ def resizable?; true; end
55
+
56
+ # Serialize the object from the type defined in the model to a MongoDB
57
+ # compatible object to store.
58
+ #
59
+ # @example Serialize the field.
60
+ # field.serialize(object)
61
+ #
62
+ # @param [ Object ] object The object to cast.
63
+ #
64
+ # @return [ Array ] The converted object.
65
+ #
66
+ # @since 2.1.0
67
+ def serialize(object)
68
+ object ? constraint.convert(object) : []
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
  module ForeignKeys #:nodoc:
6
6
 
7
7
  # Defines the behaviour for integer foreign key fields.
@@ -37,7 +37,16 @@ module Mongoid #:nodoc:
37
37
  if object_id_field?
38
38
  constraint.convert(object)
39
39
  else
40
- metadata.klass.fields["_id"].serialize(object)
40
+ case object
41
+ when ::Array
42
+ object.replace(object.map { |arg| serialize(arg) })
43
+ when ::Hash
44
+ object.each_pair do |key, value|
45
+ object[key] = serialize(value)
46
+ end
47
+ else
48
+ metadata.klass.fields["_id"].serialize(object)
49
+ end
41
50
  end
42
51
  end
43
52
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
  # Defines the behaviour for hash fields.
6
6
  class Hash
7
7
  include Serializable
@@ -1,12 +1,27 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for integer fields.
7
7
  class Integer
8
8
  include Serializable
9
9
 
10
+ # Special case to serialize the object.
11
+ #
12
+ # @example Convert to a selection.
13
+ # field.selection(object)
14
+ #
15
+ # @param [ Object ] The object to convert.
16
+ #
17
+ # @return [ Object ] The converted object.
18
+ #
19
+ # @since 2.4.0
20
+ def selection(object)
21
+ return object if object.is_a?(::Hash)
22
+ serialize(object)
23
+ end
24
+
10
25
  # Serialize the object from the type defined in the model to a MongoDB
11
26
  # compatible object to store.
12
27
  #
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for localized string fields.
7
7
  class Localized
@@ -19,7 +19,28 @@ module Mongoid #:nodoc:
19
19
  #
20
20
  # @since 2.3.0
21
21
  def deserialize(object)
22
- object[::I18n.locale.to_s]
22
+ return nil if object.nil?
23
+ locale = ::I18n.locale
24
+ if ::I18n.respond_to?(:fallbacks)
25
+ object[::I18n.fallbacks[locale].map(&:to_s).find{ |loc| object[loc] }]
26
+ else
27
+ object[locale.to_s]
28
+ end
29
+ end
30
+
31
+ # Special case to serialize the object.
32
+ #
33
+ # @example Convert to a selection.
34
+ # field.selection(object)
35
+ #
36
+ # @param [ Object ] The object to convert.
37
+ #
38
+ # @return [ Object ] The converted object.
39
+ #
40
+ # @since 2.4.0
41
+ def selection(object)
42
+ return object if object.is_a?(::Hash)
43
+ serialize(object)
23
44
  end
24
45
 
25
46
  # Convert the provided string into a hash for the locale.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for nil fields.
7
7
  class NilClass
@@ -20,6 +20,21 @@ module Mongoid #:nodoc:
20
20
  # @since 2.1.0
21
21
  def deserialize(object); nil; end
22
22
 
23
+ # Special case to serialize the object.
24
+ #
25
+ # @example Convert to a selection.
26
+ # field.selection(object)
27
+ #
28
+ # @param [ Object ] The object to convert.
29
+ #
30
+ # @return [ Object ] The converted object.
31
+ #
32
+ # @since 2.4.0
33
+ def selection(object)
34
+ return object if object.is_a?(::Hash)
35
+ serialize(object)
36
+ end
37
+
23
38
  # Serialize the object from the type defined in the model to a MongoDB
24
39
  # compatible object to store.
25
40
  #
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
  # Defines the behaviour for object fields.
6
6
  class Object
7
7
  include Serializable
@@ -1,12 +1,27 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for BSON::ObjectId fields.
7
7
  class ObjectId
8
8
  include Serializable
9
9
 
10
+ # Special case to serialize the object.
11
+ #
12
+ # @example Convert to a selection.
13
+ # field.selection(object)
14
+ #
15
+ # @param [ Object ] The object to convert.
16
+ #
17
+ # @return [ Object ] The converted object.
18
+ #
19
+ # @since 2.4.0
20
+ def selection(object)
21
+ return object if object.is_a?(::Hash)
22
+ serialize(object)
23
+ end
24
+
10
25
  # Serialize the object from the type defined in the model to a MongoDB
11
26
  # compatible object to store.
12
27
  #
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for range fields.
7
7
  class Range
@@ -22,6 +22,25 @@ module Mongoid #:nodoc:
22
22
  object.nil? ? nil : ::Range.new(object["min"], object["max"])
23
23
  end
24
24
 
25
+ # Convert the provided object to a Mongoid criteria friendly value. For
26
+ # ranges this will look for something between the min and max values.
27
+ #
28
+ # @example Convert the field.
29
+ # field.selection(object)
30
+ #
31
+ # @param [ Object ] The object to convert.
32
+ #
33
+ # @return [ Object ] The converted object.
34
+ #
35
+ # @since 2.4.0
36
+ def selection(object)
37
+ return object if object.is_a?(::Hash)
38
+ {
39
+ "min" => { "$gte" => object.first },
40
+ "max" => { "$lte" => object.last }
41
+ }
42
+ end
43
+
25
44
  # Serialize the object from the type defined in the model to a MongoDB
26
45
  # compatible object to store.
27
46
  #
@@ -34,7 +53,7 @@ module Mongoid #:nodoc:
34
53
  #
35
54
  # @since 2.1.0
36
55
  def serialize(object)
37
- object.nil? ? nil : { "min" => object.min, "max" => object.max }
56
+ object.nil? ? nil : { "min" => object.first, "max" => object.last }
38
57
  end
39
58
  end
40
59
  end