Putting it all together
Our business partner just informed us that we want to be able to record transaction receipts for every applicable event. This could be for the boarding ticket, extra luggage, or an additional water bottle, which means there is no deterministic structure for our data. For this task, we will need to generate a new model, Receipts
, and update our BoardingTicket
model. Here are the steps:
- First, we can begin by generating a new model called
Receipts
for storing transaction events:sequelize-cli model:generate --name Receipts --attributes receipt:json
- Then, run our migration:
sequelize db:migrate
- Next, we will want to add another life cycle event to our
BoardingTicket
model located inmodels/boardingticket.js
by adding the following code at the end of themodule.exports
block:BoardingTicket.afterSave('saveReceipt', async(ticket, options) => { await sequelize.models...