Display all bands grouped by genre, create m:n association between Band and Genre in database
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { BelongsTo, Column, DataType, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
|
||||
import { BelongsTo, BelongsToMany, Column, DataType, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
|
||||
import { Member } from "./member.model";
|
||||
import { Genre } from "./genre.model";
|
||||
import { Rating } from "./rating.model";
|
||||
import { Tour } from "./tour.model";
|
||||
import { BandGenre } from "./bandGenre.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Band extends Model {
|
||||
@@ -32,10 +33,6 @@ export class Band extends Model {
|
||||
@Column
|
||||
logo: String
|
||||
|
||||
@ForeignKey(() => Genre)
|
||||
@Column
|
||||
genreId: Number
|
||||
|
||||
|
||||
// Relations
|
||||
|
||||
@@ -48,6 +45,6 @@ export class Band extends Model {
|
||||
@HasMany(() => Tour)
|
||||
tours: Tour[]
|
||||
|
||||
@BelongsTo(() => Genre)
|
||||
genre: Genre
|
||||
@BelongsToMany(() => Genre, () => BandGenre)
|
||||
genres: Genre[]
|
||||
}
|
||||
16
software/backend/models/acts/bandGenre.model.ts
Normal file
16
software/backend/models/acts/bandGenre.model.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { AutoIncrement, Column, ForeignKey, Model, PrimaryKey, Table, Unique } from "sequelize-typescript";
|
||||
import { Genre } from "./genre.model";
|
||||
import { Band } from "./band.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class BandGenre extends Model {
|
||||
@PrimaryKey
|
||||
@Column({autoIncrement: true})
|
||||
declare id: number
|
||||
|
||||
@ForeignKey(() => Genre)
|
||||
genreId: number
|
||||
|
||||
@ForeignKey(() => Band)
|
||||
bandId: number
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Column, HasMany, Model, Table } from "sequelize-typescript";
|
||||
import { BelongsToMany, Column, Model, Table } from "sequelize-typescript";
|
||||
import { Band } from "./band.model";
|
||||
import { BandGenre } from "./bandGenre.model";
|
||||
|
||||
@Table({ timestamps: false })
|
||||
export class Genre extends Model {
|
||||
@@ -9,6 +10,6 @@ export class Genre extends Model {
|
||||
|
||||
// Relations
|
||||
|
||||
@HasMany(() => Band)
|
||||
@BelongsToMany(() => Band, () => BandGenre)
|
||||
bands: Band[]
|
||||
}
|
||||
Reference in New Issue
Block a user