mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Unable to set reverse_delte_rule to GenericReferenceField. AttributeError: 'GenericReferenceField' object has no attribute 'document_type'

Open chavus opened this issue 5 years ago • 2 comments

I get the following error when trying to add "reverse_delete_rule=db.CASCADE" to a GenericReferenceField:

AttributeError: 'GenericReferenceField' object has no attribute 'document_type'

This is my code:

`from database.db import db

class Movie(db.DynamicDocument): name = db.StringField(required=True, unique=True) casts = db.ListField(db.StringField) genres = db.ListField(db.StringField) directors = db.GenericReferenceField(reverse_delete_rule=db.CASCADE) `

This is the error: AttributeError: 'GenericReferenceField' object has no attribute 'document_type'

My understanding is that GenericReferenceField inherits ReferenceField attributes.

chavus avatar Apr 23 '20 04:04 chavus

its not working ,u can use numbers 0.,1,2,3,4

softwolves avatar Feb 22 '21 08:02 softwolves

GenericReferenceField does not inherit from ReferenceField. Currently MongoEngine does not support reverse delete rules for GenericReferenceField.

This could be fixed in multiple ways, either by having GenericReferenceField check every defined Document upon deletion (expensive and honestly not sure if this feature should be given to users given the performance concerns) or by allowing reverse delete rules when the GenericReferenceField defines a set of choices for documents it can reference, then checking that smaller set of document upon delete.

combscCode avatar Jul 27 '23 15:07 combscCode