I'm wondering where in the process of creating objects and storing them in the database the primary key gets assigned by SQLAlchemy. In my app, when something happens I create an Event for that 'happening' and then create a notification for each user that needs to know about that Event. This all happens in the same method.
The problem now is that the Notification references the Event. Should I connect twice to the database to achieve this? First to store the Event so it gets assigned a primary key and secondly to store the notification? Is it possible to only connect once to the database?
So these steps should happen:
- User does something
- Create an Event
- Necessary? Store the Event in the database so I get a primary key to reference to
- Create a Notification that references the Event
- Store the Notification