0

If I have two models, User and Address, and they reference each other like this:

# usermodel.py
from address import Address
from mongoengine import *
class User(Document):
    name = StringField()
    address = ReferenceField(Address)

# address.py
from mongoengine import *
class Address(Document):
     owner = ReferenceField('User', reverse_delete_rule=2)

I get the error message:

NotRegistered('`User` has not been registered in the document registry.
Importing the document class automatically registers it, has it been imported?',)

Can I set up a signal on one document and a reverse_delete_rule on another? I believe this is happening because reverse_delete_rule needs to register the document.

Rob
  • 3,333
  • 5
  • 28
  • 71
  • 1
    You've edited code but not description. "If I have two models, `User` and `FriendRequest`" there is no `FriendRequest` – vishes_shell May 08 '17 at 19:29

1 Answers1

0

This can be solved by using the alternate notation for reverse_delete_rule:

User.register_delete_rule(Address, 'owner', CASCADE)

So the documents would be updated like this:

# usermodel.py
from address import Address
from mongoengine import *
class User(Document):
    name = StringField()
    address = ReferenceField(Address)

User.register_delete_rule(Address, 'owner', CASCADE)

# address.py
from mongoengine import *
class Address(Document):
     owner = ReferenceField('User')
Rob
  • 3,333
  • 5
  • 28
  • 71