Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09db486

Browse files
committed
Made objectify idempotent.
1 parent 1f6aaa7 commit 09db486

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib.coffee

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,16 @@ class globals.Document
107107

108108
if field.isArray
109109
throw new Error "Document does not match schema, not an array" unless _.isArray obj[name]
110-
obj[name] = _.map obj[name], (o) => new field.targetDocument o
110+
obj[name] = _.map obj[name], (o) =>
111+
if o instanceof field.targetDocument
112+
o
113+
else
114+
new field.targetDocument o
111115
else
112116
throw new Error "Document does not match schema, ancestorArray does not match: #{ field.ancestorArray } vs. #{ ancestorArray }" if field.ancestorArray isnt ancestorArray
113117
throw new Error "Document does not match schema, not a plain object" unless isPlainObject obj[name]
114-
obj[name] = new field.targetDocument obj[name]
118+
if obj[name] not instanceof field.targetDocument
119+
obj[name] = new field.targetDocument obj[name]
115120

116121
else if isPlainObject field
117122
if _.isArray obj[name]

0 commit comments

Comments
 (0)