parent
a6948771d8
commit
e9d7353294
@ -5,6 +5,7 @@ Changelog
|
||||
Changes in dev
|
||||
==============
|
||||
|
||||
- Added InvalidQueryError when calling with_id with a filter
|
||||
- Added support for DBRefs in distinct()
|
||||
- Fixed issue saving False booleans
|
||||
- Fixed issue with dynamic documents deltas
|
||||
|
@ -13,6 +13,7 @@ an InvalidDocument error as they aren't currently supported.
|
||||
|
||||
Document._get_subclasses - Is no longer used and the class method has been removed.
|
||||
|
||||
Document.objects.with_id - now raises an InvalidQueryError if used with a filter.
|
||||
|
||||
0.4 to 0.5
|
||||
===========
|
||||
|
@ -858,10 +858,16 @@ class QuerySet(object):
|
||||
return return_one and results[0] or results
|
||||
|
||||
def with_id(self, object_id):
|
||||
"""Retrieve the object matching the id provided.
|
||||
"""Retrieve the object matching the id provided. Uses `object_id` only
|
||||
and raises InvalidQueryError if a filter has been applied.
|
||||
|
||||
:param object_id: the value for the id of the document to look up
|
||||
|
||||
.. versionchanged:: 0.6 Raises InvalidQueryError if filter has been set
|
||||
"""
|
||||
if not self._query_obj.empty:
|
||||
raise InvalidQueryError("Cannot use a filter whilst using `with_id`")
|
||||
|
||||
return self._document.objects(pk=object_id).first()
|
||||
|
||||
def in_bulk(self, object_ids):
|
||||
|
@ -154,6 +154,8 @@ class QuerySetTest(unittest.TestCase):
|
||||
person = self.Person.objects.with_id(person1.id)
|
||||
self.assertEqual(person.name, "User A")
|
||||
|
||||
self.assertRaises(InvalidQueryError, self.Person.objects(name="User A").with_id, person1.id)
|
||||
|
||||
def test_find_only_one(self):
|
||||
"""Ensure that a query using ``get`` returns at most one result.
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user