Created
December 3, 2010 16:38
-
-
Save hmarr/727195 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mongoengine import * | |
from mongoengine.queryset import QuerySet | |
class PostQuerySet(QuerySet): | |
def delete(self, safe=False): | |
ids = [post.id for post in self] | |
Comment.objects(post__in=ids).delete(safe=safe) | |
super(PostQuerySet, self).delete(safe=safe) | |
class Post(Document): | |
title = StringField() | |
meta = {'queryset_class': PostQuerySet} | |
def delete(self, safe=False): | |
Comment.objects(post=self.id).delete(safe=safe) | |
super(Post, self).delete(safe=safe) | |
class Comment(Document): | |
post = ReferenceField(Post) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that this might just work, but the implementation is very ad hoc. I'd have to know upfront which objects refer to the Post document, which is not really useful when building extensible applications. I've forked this Gist and I'm preparing a patch that implements the idea (at least in pseudo code for now) that solves this problem in a general sense. Hang on.