Mongoengine: Bi-Directional relationships + reverse_delete_rule

Created on 8 May 2012  路  1Comment  路  Source: MongoEngine/mongoengine

I've discovered a potential bug when implementing Bi-Directional relationships + reverse_delete_rule.

Here is the code that work:

from mongoengine import *
class Foo(Document):
bar = ReferenceField('Bar')

class Bar(Document):
foo = ReferenceField(Foo)

Here is the code that NOT work:

from mongoengine import *
class Foo(Document):
bar = ReferenceField('Bar', reverse_delete_rule=NULLIFY)

class Bar(Document):
foo = ReferenceField(Foo, reverse_delete_rule=NULLIFY)

Most helpful comment

Hi something like this should work:

    class Bar(Document):
        content = StringField()
        foo = ReferenceField('Foo')

    class Foo(Document):
        content = StringField()
        bar = ReferenceField(Bar)

    Bar.register_delete_rule(Foo, 'bar', NULLIFY)
    Foo.register_delete_rule(Bar, 'foo', NULLIFY)

I've update the docs

>All comments

Hi something like this should work:

    class Bar(Document):
        content = StringField()
        foo = ReferenceField('Foo')

    class Foo(Document):
        content = StringField()
        bar = ReferenceField(Bar)

    Bar.register_delete_rule(Foo, 'bar', NULLIFY)
    Foo.register_delete_rule(Bar, 'foo', NULLIFY)

I've update the docs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tenspd137 picture tenspd137  路  4Comments

knoxxs picture knoxxs  路  3Comments

MateuszBelczowski picture MateuszBelczowski  路  4Comments

mlorant picture mlorant  路  5Comments

kevin0571 picture kevin0571  路  3Comments