Hi all,
I'm using Python 3.6, Flask and Mongoengine to build a web app, in the app I have 2 classes.
class PayMethods(BaseDocument):
name = StringField(required=True, max_length=200, unique=True)
class Expense(BaseDocument):
amount = IntField()
descreption = StringField(required=True, max_length=200)
pay_method = ReferenceField(PayMethods, required=True)
I'm trying to build a One-To-Many relationship between PayMethods and Expense (Expense should have 1 and only 1 pay method and each PayMethod can be related to many expenses).
I notice that I can create a new Expense document with a PayMethod that doesn't exist yet in the DB. Why is that? why is that not prevented on the DB level? I only see an error while I'm trying to fetch the "new" document from the DB.
Is there a flag that I need to use to make the DB enforce this relesnship?