              {'url': 'http://testserver/manytomanytarget/1/', 'name': 'target-1', 'sources': ['http://testserver/manytomanysource/1/', 'http://testserver/manytomanysource/2/', 'http://testserver/manytomanysource/3/']},
              {'url': 'http://testserver/manytomanytarget/2/', 'name': 'target-2', 'sources': ['http://testserver/manytomanysource/2/', 'http://testserver/manytomanysource/3/']},
              {'url': 'http://testserver/manytomanytarget/3/', 'name': 'target-3', 'sources': ['http://testserver/manytomanysource/3/']}
          ]
          self.assertEqual(serializer.data, expected)
  
      def test_many_to_many_update(self):
          data = {'url': 'http://testserver/manytomanysource/1/', 'name': 'source-1', 'targets': ['http://testserver/manytomanytarget/1/', 'http://testserver/manytomanytarget/2/', 'http://testserver/manytomanytarget/3/']}
          instance = ManyToManySource.objects.get(pk=1)
          serializer = ManyToManySourceSerializer(instance, data=data, context={'request': request})
 
</s> remove         self.assertEqual(serializer.data, expected)
 </s> add         with self.assertNumQueries(3):
            self.assertEqual(serializer.data, expected) </s> remove         self.assertEqual(serializer.data, expected)
 </s> add         with self.assertNumQueries(4):
            self.assertEqual(serializer.data, expected) </s> remove         self.assertEqual(serializer.data, expected)
 </s> add         with self.assertNumQueries(1):
            self.assertEqual(serializer.data, expected) </s> remove         return relationship.all() if (hasattr(relationship, 'all')) else relationship
 </s> add         relationship = relationship.all() if (hasattr(relationship, 'all')) else relationship

        if self.use_pk_only_optimization():
            # Optimized case, return mock objects only containing the pk attribute.
            return [
                PKOnlyObject(pk=pk)
                for pk in relationship.values_list('pk', flat=True)
            ]

        # Standard case, return the object instances.
        return relationship
        with self.assertNumQueries(4):
            self.assertEqual(serializer.data, expected)
              {'url': 'http://testserver/manytomanytarget/1/', 'name': 'target-1', 'sources': ['http://testserver/manytomanysource/1/', 'http://testserver/manytomanysource/2/', 'http://testserver/manytomanysource/3/']},
              {'url': 'http://testserver/manytomanytarget/2/', 'name': 'target-2', 'sources': ['http://testserver/manytomanysource/2/', 'http://testserver/manytomanysource/3/']},
              {'url': 'http://testserver/manytomanytarget/3/', 'name': 'target-3', 'sources': ['http://testserver/manytomanysource/3/']}
          ]
        with self.assertNumQueries(4):
            self.assertEqual(serializer.data, expected)
  
      def test_many_to_many_update(self):
          data = {'url': 'http://testserver/manytomanysource/1/', 'name': 'source-1', 'targets': ['http://testserver/manytomanytarget/1/', 'http://testserver/manytomanytarget/2/', 'http://testserver/manytomanytarget/3/']}
          instance = ManyToManySource.objects.get(pk=1)
          serializer = ManyToManySourceSerializer(instance, data=data, context={'request': request})
keep keep keep keep replace keep keep keep keep keep
 Hyperlinked PK optimization. Closes #1872. 
tests/test_relations_hyperlink.py