'Ensure that a referenced document with custom primary key
is also deleted upon deletion.'

def test_reverse_delete_rule_with_custom_id_field(self):

    class User(Document, ):
        name = StringField(primary_key=True)
    class Book(Document, ):
        author = ReferenceField(User, reverse_delete_rule=CASCADE)
        reviewer = ReferenceField(User, reverse_delete_rule=NULLIFY)
    User.drop_collection()
    Book.drop_collection()
    user = User(name='Mike').save()
    reviewer = User(name='John').save()
    book = Book(author=user, reviewer=reviewer).save()
    reviewer.delete()
    self.assertEqual(Book.objects.count(), 1)
    self.assertEqual(Book.objects.get().reviewer, None)
    user.delete()
    self.assertEqual(Book.objects.count(), 0)
