Managed Transactions and Syncing Movie Cast Members

In this lesson, we'll learn how we can use what we learned in the last lesson to also sync our cast members. We'll then extract this functionality into a service and wrap it within a managed database transactions.

Published
Jun 26, 24
Duration
15m 55s

Developer, dog lover, and burrito eater. Currently teaching AdonisJS, a fully featured NodeJS framework, and running Adocasts where I post new lessons weekly. Professionally, I work with JavaScript, .Net C#, and SQL Server.

Adocasts

Burlington, KY

🕰️ Chapters
00:00 - Querying the Movies Cast Members
01:24 - Defining Our Cast Member Form Fields
03:45 - Defining Our Cast Member Validations
04:40 - Syncing Our Movie Cast Members
05:40 - Extracting Our Cast and Crew Member Sync into a Service
08:07 - Introducing Managed Database Transactions
11:10 - Fixing Our AlpineJS Loop Keys
11:55 - Testing Our Sync Behavior

Join The Discussion! (2 Comments)

Please sign in or sign up for free to join in on the dicussion.

  1. Commented 19 days ago

    Hello,

    I'm going to bother you again. 😆 I think there’s still an issue, especially when you add or remove the same person since they share the same cineast_id. I believe we should generate a unique ID, using something like Math.random() as a quick solution, to avoid relying on cineast_id.

    1

    Please sign in or sign up for free to reply

    1. Commented 14 days ago

      Yep - you're absolutely right, sorry about that! Tacking one more property into the object specifically to uniquely identify the row would fix it up and Math.random() is usually what I reach for as well for those use cases.

      I like to use the below because the _ prefix ensures it can also be used in the id attribute if needed.

      const uniqueId = '_' + Math.random().toString(36).substr(2, 9)
      Copied!
      0

      Please sign in or sign up for free to reply