Display all bands grouped by genre, create m:n association between Band and Genre in database

This commit is contained in:
2024-09-27 23:25:24 +02:00
parent 848e7abf92
commit 9b325c849e
29 changed files with 275 additions and 165 deletions

View File

@@ -12,6 +12,7 @@ import { Location } from '../models/acts/location.model'
import { Show } from '../models/acts/show.model'
import { Tour } from '../models/acts/tour.model'
import { City } from '../models/acts/city.model'
import { BandGenre } from '../models/acts/bandGenre.model'
import accounts from "./../data/accounts.json"
import orders from "./../data/orders.json"
@@ -69,8 +70,17 @@ export async function prepopulateDatabase() {
for(let band of bands.data) {
// Create a band dataset
await Band.create(band)
.then(dataset => {
.then(async dataset => {
// Create the m:n associations for the genres
for (let genreId of band.genreId) {
await BandGenre.create({
genreId: Number(genreId),
bandId: dataset.dataValues.id
})
}
Rating.bulkCreate(band.ratings)
Member.bulkCreate(band.members)
})