Merge remote-tracking branch 'origin/pr/312' into 312
This commit is contained in:
commit
941042d0ba
@ -569,6 +569,15 @@ class QuerySet(object):
|
||||
queryset._none = True
|
||||
return queryset
|
||||
|
||||
def disable_inheritance(self):
|
||||
"""
|
||||
Disable inheritance query, fetch only objects for the query class
|
||||
"""
|
||||
if self._document._meta.get('allow_inheritance') is True:
|
||||
self._initial_query = {"_cls": self._document._class_name}
|
||||
|
||||
return self
|
||||
|
||||
def clone(self):
|
||||
"""Creates a copy of the current
|
||||
:class:`~mongoengine.queryset.QuerySet`
|
||||
|
@ -3322,5 +3322,25 @@ class QuerySetTest(unittest.TestCase):
|
||||
|
||||
self.assertEqual(q, 2)
|
||||
|
||||
def test_disable_inheritance_queryset(self):
|
||||
class A(Document):
|
||||
x = IntField()
|
||||
y = IntField()
|
||||
|
||||
meta = {'allow_inheritance': True}
|
||||
|
||||
class B(A):
|
||||
z = IntField()
|
||||
|
||||
A.drop_collection()
|
||||
|
||||
A(x=10, y=20).save()
|
||||
A(x=15, y=30).save()
|
||||
B(x=20, y=40).save()
|
||||
B(x=30, y=50).save()
|
||||
|
||||
for obj in A.objects.disable_inheritance():
|
||||
self.assertEqual(obj.__class__, A)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user