Updated inheritable objects created by upsert now contain _cls (MongoEngine/mongoengine#118)

This commit is contained in:
Ross Lawley
2012-11-08 16:35:20 +00:00
parent 363e50abbe
commit f265915aa2
3 changed files with 30 additions and 2 deletions

View File

@@ -824,8 +824,16 @@ class QuerySet(object):
if not write_options:
write_options = {}
update = transform.update(self._document, **update)
query = self._query
update = transform.update(self._document, **update)
# If doing an atomic upsert on an inheritable class
# then ensure we add _cls to the update operation
if upsert and '_cls' in query:
if '$set' in update:
update["$set"]["_cls"] = self._document._class_name
else:
update["$set"] = {"_cls": self._document._class_name}
try:
ret = self._collection.update(query, update, multi=multi,
@@ -852,7 +860,7 @@ class QuerySet(object):
.. versionadded:: 0.2
"""
return self.update(safe_update=True, upsert=False, multi=False,
return self.update(safe_update=True, upsert=upsert, multi=False,
write_options=None, **update)
def __iter__(self):