Merge remote-tracking branch 'origin/pr/254'
This commit is contained in:
		
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							| @@ -128,3 +128,4 @@ that much better: | |||||||
|  * Peter Teichman |  * Peter Teichman | ||||||
|  * Jakub Kot |  * Jakub Kot | ||||||
|  * Jorge Bastida |  * Jorge Bastida | ||||||
|  |  * Aleksandr Sorokoumov | ||||||
| @@ -367,6 +367,10 @@ class QuerySet(object): | |||||||
|         self._skip = None |         self._skip = None | ||||||
|         self._hint = -1  # Using -1 as None is a valid value for hint |         self._hint = -1  # Using -1 as None is a valid value for hint | ||||||
|  |  | ||||||
|  |     def __deepcopy__(self, memo): | ||||||
|  |         """Essential for chained queries with ReferenceFields involved""" | ||||||
|  |         return self.clone() | ||||||
|  |  | ||||||
|     def clone(self): |     def clone(self): | ||||||
|         """Creates a copy of the current :class:`~mongoengine.queryset.QuerySet` |         """Creates a copy of the current :class:`~mongoengine.queryset.QuerySet` | ||||||
|  |  | ||||||
| @@ -814,7 +818,6 @@ class QuerySet(object): | |||||||
|                     mongo_query['$and'].append(value) |                     mongo_query['$and'].append(value) | ||||||
|                 else: |                 else: | ||||||
|                     mongo_query['$and'] = value |                     mongo_query['$and'] = value | ||||||
|  |  | ||||||
|         return mongo_query |         return mongo_query | ||||||
|  |  | ||||||
|     def get(self, *q_objs, **query): |     def get(self, *q_objs, **query): | ||||||
|   | |||||||
| @@ -232,28 +232,33 @@ class QuerySetTest(unittest.TestCase): | |||||||
|  |  | ||||||
|     def test_chaining(self): |     def test_chaining(self): | ||||||
|         class A(Document): |         class A(Document): | ||||||
|             pass |             s = StringField() | ||||||
|  |  | ||||||
|         class B(Document): |         class B(Document): | ||||||
|             a = ReferenceField(A) |             ref = ReferenceField(A) | ||||||
|  |             boolfield = BooleanField(default=False) | ||||||
|  |  | ||||||
|         A.drop_collection() |         A.drop_collection() | ||||||
|         B.drop_collection() |         B.drop_collection() | ||||||
|  |  | ||||||
|         a1 = A().save() |         a1 = A(s="test1").save() | ||||||
|         a2 = A().save() |         a2 = A(s="test2").save() | ||||||
|  |  | ||||||
|         B(a=a1).save() |         B(ref=a1, boolfield=True).save() | ||||||
|  |  | ||||||
|         # Works |         # Works | ||||||
|         q1 = B.objects.filter(a__in=[a1, a2], a=a1)._query |         q1 = B.objects.filter(ref__in=[a1, a2], ref=a1)._query | ||||||
|  |  | ||||||
|         # Doesn't work |         # Doesn't work | ||||||
|         q2 = B.objects.filter(a__in=[a1, a2]) |         q2 = B.objects.filter(ref__in=[a1, a2]) | ||||||
|         q2 = q2.filter(a=a1)._query |         q2 = q2.filter(ref=a1)._query | ||||||
|  |  | ||||||
|         self.assertEqual(q1, q2) |         self.assertEqual(q1, q2) | ||||||
|  |  | ||||||
|  |         a_objects = A.objects(s='test1') | ||||||
|  |         query = B.objects(ref__in=a_objects) | ||||||
|  |         query = query.filter(boolfield=True) | ||||||
|  |         self.assertEquals(query.count(), 1) | ||||||
|  |  | ||||||
|     def test_update_write_options(self): |     def test_update_write_options(self): | ||||||
|         """Test that passing write_options works""" |         """Test that passing write_options works""" | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user