Applying associations to Avalon Airlines
Luckily, the models for the project are simple and won’t require the amount of effort as defining a Super Many-to-Many relationship. Within these next several model updates, this book will demonstrate what to modify only for the class
model block (the rest of the contents within each file should remain the same).
Starting in alphabetical order, we will begin modifying the models/airplane.js
file’s class
block by adding a relationship to FlightSchedule
:
class Airplane extends Model { static associate(models) { this.FlightSchedules = this.hasMany(models.FlightSchedule); } };
Next, we can edit the models/boardingticket.js
file’s class
block and add a Customer
and FlightSchedule
relationship:
class BoardingTicket extends Model { static associate(models) { this.Customer = this.belongsTo(models['Customer']); this.FlightSchedule...