Python for Entrepreneurs Transcripts
Chapter: Accessing databases from Python: SQLAlchemy ORM
Lecture: Demo: Review of creating albums

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So let's review, real quickly. The core element of what we did was this create album method, so we created an album and we gave it the data needed,
0:10 the way we did this is we create a session using the session factory, in this case we were inserting so we allocate new objects
0:16 and add them to the session, we want to add some related dependent objects like these tracks, so we go and use our relationship that we have,
0:24 we append to the tracks and when things got inserted, all the foreign key relationships for the auto-incremented ids were all worked out
0:32 we called commit, we returned the album, we did a little print, we haven't looked at that yet but somewhere in here
0:38 there should be created a new album with id 2. So you can see that after we called commit our album
0:46 now actually had its primary key back which we can use for all sorts of things, you maybe want to use this for further processing in your app.


Talk Python's Mastodon Michael Kennedy's Mastodon