-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
nickfrev/mongoengine
#1Labels
Description
When saving a document with a ReferenceField holding a new object, I get an error:
mongoengine.errors.ValidationError: ValidationError
You can only reference documents once they have been saved to the database
I naively expected cascade=True to automatically save the new document, while apparently it only automatically saves changes to existing documents.
Is this something that could be changed or is it meant to be for good reasons?
Example:
class User(Document):
name = StringField()
class UserSubscription(Document):
name = StringField()
user = ReferenceField(User, dbref=False)
User.drop_collection()
UserSubscription.drop_collection()
# u1 = User(name="Ross").save()
u1 = User(name="Ross")
sub = UserSubscription(user=u1).save()I'd like this not to throw ValidationError but to save u1 in cascade.
perseus-me, AgarwalPragy, doaa-altarawy, zipzapp, MohamedAmineOuali and 6 more