File tree 5 files changed +37
-5
lines changed 5 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,8 @@ def over_limit?(attributes)
101
101
# @param [ Hash ] attrs The single document attributes to process.
102
102
def process_attributes ( parent , attrs )
103
103
return if reject? ( parent , attrs )
104
- if id = attrs . extract_id
104
+
105
+ if ( id = extract_id ( attrs ) )
105
106
update_nested_relation ( parent , id , attrs )
106
107
else
107
108
existing . push ( Factory . build ( @class_name , attrs ) ) unless destroyable? ( attrs )
@@ -153,7 +154,7 @@ def destroy_document(relation, doc)
153
154
# @param [ Document ] doc The document to update.
154
155
# @param [ Hash ] attrs The attributes.
155
156
def update_document ( doc , attrs )
156
- attrs . delete_id
157
+ delete_id ( attrs )
157
158
if association . embedded?
158
159
doc . assign_attributes ( attrs )
159
160
else
Original file line number Diff line number Diff line change @@ -65,6 +65,33 @@ def update_only?
65
65
def convert_id ( klass , id )
66
66
klass . using_object_ids? ? BSON ::ObjectId . mongoize ( id ) : id
67
67
end
68
+
69
+ private
70
+
71
+ # Get the id attribute from the given hash, whether it's
72
+ # prefixed with an underscore or is a symbol.
73
+ #
74
+ # @example Get the id.
75
+ # extract_id({ _id: 1 })
76
+ #
77
+ # @param [ Hash ] hash The hash from which to extract.
78
+ #
79
+ # @return [ Object ] The value of the id.
80
+ def extract_id ( hash )
81
+ hash [ '_id' ] || hash [ :_id ] || hash [ 'id' ] || hash [ :id ]
82
+ end
83
+
84
+ # Deletes the id key from the given hash.
85
+ #
86
+ # @example Delete an id value.
87
+ # delete_id({ "_id" => 1 })
88
+ #
89
+ # @param [ Hash ] hash The hash from which to delete.
90
+ #
91
+ # @return [ Object ] The deleted value, or nil.
92
+ def delete_id ( hash )
93
+ hash . delete ( '_id' ) || hash . delete ( :_id ) || hash . delete ( 'id' ) || hash . delete ( :id )
94
+ end
68
95
end
69
96
end
70
97
end
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def build(parent)
29
29
return if reject? ( parent , attributes )
30
30
@existing = parent . send ( association . name )
31
31
if update?
32
- attributes . delete_id
32
+ delete_id ( attributes )
33
33
existing . assign_attributes ( attributes )
34
34
elsif replace?
35
35
parent . send ( association . setter , Factory . build ( @class_name , attributes ) )
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ def embedded?
162
162
#
163
163
# @return [ Object ] The id.
164
164
def extract_id
165
- selector . extract_id
165
+ selector [ '_id' ] || selector [ :_id ] || selector [ 'id' ] || selector [ :id ]
166
166
end
167
167
168
168
# Adds a criterion to the +Criteria+ that specifies additional options
@@ -225,7 +225,7 @@ def initialize(klass)
225
225
# may be desired.
226
226
#
227
227
# @example Merge the criteria with another criteria.
228
- # criteri .merge(other_criteria)
228
+ # criteria .merge(other_criteria)
229
229
#
230
230
# @example Merge the criteria with a hash. The hash must contain a klass
231
231
# key and the key/value pairs correspond to method names/args.
Original file line number Diff line number Diff line change @@ -101,9 +101,11 @@ def _mongoid_unsatisfiable_criteria?
101
101
# {}.delete_id
102
102
#
103
103
# @return [ Object ] The deleted value, or nil.
104
+ # @deprecated
104
105
def delete_id
105
106
delete ( "_id" ) || delete ( :_id ) || delete ( "id" ) || delete ( :id )
106
107
end
108
+ Mongoid . deprecate ( self , :delete_id )
107
109
108
110
# Get the id attribute from this hash, whether it's prefixed with an
109
111
# underscore or is a symbol.
@@ -112,9 +114,11 @@ def delete_id
112
114
# { :_id => 1 }.extract_id
113
115
#
114
116
# @return [ Object ] The value of the id.
117
+ # @deprecated
115
118
def extract_id
116
119
self [ "_id" ] || self [ :_id ] || self [ "id" ] || self [ :id ]
117
120
end
121
+ Mongoid . deprecate ( self , :extract_id )
118
122
119
123
# Turn the object from the ruby type we deal with to a Mongo friendly
120
124
# type.
You can’t perform that action at this time.
0 commit comments