Python for Entrepreneurs Transcripts
Chapter: Accessing databases from Python: SQLAlchemy ORM
Lecture: Demo: Review of creating albums
0:00 So let's review, real quickly.
0:03 The core element of what we did was this create album method,
0:06 so we created an album and we gave it the data needed,
0:09 the way we did this is we create a session using the session factory,
0:12 in this case we were inserting so we allocate new objects
0:15 and add them to the session,
0:17 we want to add some related dependent objects like these tracks,
0:20 so we go and use our relationship that we have,
0:23 we append to the tracks and when things got inserted,
0:26 all the foreign key relationships
0:28 for the auto-incremented ids were all worked out
0:31 we called commit, we returned the album, we did a little print,
0:34 we haven't looked at that yet but somewhere in here
0:37 there should be created a new album with id 2.
0:41 So you can see that after we called commit our album
0:45 now actually had its primary key back which we can use for all sorts of things,
0:50 you maybe want to use this for further processing in your app.