You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class A(Document):
name = StringField()
ref_b= ListField(ReferenceField('B', reverse_delete_rule=PULL))
class B(Document):
content = StringField()
ref_a = ReferenceField('A', reverse_delete_rule=NULLIFY)
User Doc has a forward references Page, when i set a reverse_delete_rule other than DO_NOTHING,it will raise mongoengine.errors.NotRegistered: `B` has not been registered in the document registry. Importing the document class automatically registers it, has it been imported?
I want to automatically delete reference when I delete document
how can i avoid this Exception?
The text was updated successfully, but these errors were encountered:
I worked around this by separating the delete rule for model that referenced the "unregistered" model. I had to register the delete rule for the model defined first(User in your example). Yours would look like this I think:
class User(Document):
name = StringField()
ref_page= ListField(ReferenceField('Page'))
class Page(Document):
content = StringField()
ref_user = ReferenceField(User, reverse_delete_rule=NULLIFY)
User.register_delete_rule(Page, "ref_page", PULL)
code as below:
User Doc has a forward references Page, when i set a reverse_delete_rule other than DO_NOTHING,it will raise
mongoengine.errors.NotRegistered: `B` has not been registered in the document registry. Importing the document class automatically registers it, has it been imported?
I want to automatically delete reference when I delete document
how can i avoid this Exception?
The text was updated successfully, but these errors were encountered: