Permalink
Browse files

[soc2010/query-refactor] Fixed update on MongoDB.

  • Loading branch information...
1 parent 7ce8903 commit 28499bbe36c36fecf81cb8369fcb01efdc6f7160 @alex alex committed Jun 9, 2010
Showing with 14 additions and 2 deletions.
  1. +10 −1 django/contrib/mongodb/compiler.py
  2. +1 −1 django/db/models/query.py
  3. +3 −0 django/db/models/sql/compiler.py
@@ -75,4 +75,13 @@ def insert(self, return_id=False):
return self.connection.db[self.query.model._meta.db_table].insert(values)
class SQLUpdateCompiler(SQLCompiler):
- pass
+ def update(self, result_type):
+ # TODO: more asserts
+ filters = self.get_filters(self.query.where)
+ # TODO: Don't use set for everything, use INC and such where
+ # appropriate.
+ return self.connection.db[self.query.model._meta.db_table].update(
+ filters,
+ {"$set": dict((f.column, val) for f, o, val in self.query.values)},
+ multi=True
+ )
@@ -488,7 +488,7 @@ def _update(self, values):
query = self.query.clone(sql.UpdateQuery)
query.add_update_fields(values)
self._result_cache = None
- return query.get_compiler(self.db).execute_sql(None)
+ return query.get_compiler(self.db).update(None)
_update.alters_data = True
def exists(self):
@@ -866,6 +866,9 @@ def as_sql(self):
if where:
result.append('WHERE %s' % where)
return ' '.join(result), tuple(update_params + params)
+
+ def update(self, *args, **kwargs):
+ return self.execute_sql(*args, **kwargs)
def execute_sql(self, result_type):
"""

0 comments on commit 28499bb

Please sign in to comment.