我在编码方面还很新,我正在使用nestjs与PostegreSql一起创建一个应用程序 每当我尝试更新某些内容时,都会出现错误。
我具有具有@ManyToMany
关系的实体,如果我删除了这些关系,则更新工作正常。
但是,如果我允许@ManyToMany
关系,它将无法正常工作
错误消息:
[Nest] 46879 - 09/21/2019, 7:38 PM [ExceptionsHandler] column "entrainementsId" of relation "entrainements" does not exist +639401ms
[0] QueryFailedError: column "entrainementsId" of relation "entrainements" does not exist
[0] at new QueryFailedError (/Users/damien/Desktop/projetAngular/rowing/rowing-back-end/node_modules/typeorm/error/QueryFailedError.js:11:28)
[0] at Query.callback (/Users/damien/Desktop/projetAngular/rowing/rowing-back-end/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:176:38)
[0] at Query.handleError (/Users/damien/Desktop/projetAngular/rowing/rowing-back-end/node_modules/pg/lib/query.js:142:17)
[0] at Connection.connectedErrorMessageHandler (/Users/damien/Desktop/projetAngular/rowing/rowing-back-end/node_modules/pg/lib/client.js:194:17)
[0] at Connection.emit (events.js:197:13)
[0] at Socket.<anonymous> (/Users/damien/Desktop/projetAngular/rowing/rowing-back-end/node_modules/pg/lib/connection.js:126:12)
[0] at Socket.emit (events.js:197:13)
[0] at addChunk (_stream_readable.js:288:12)
[0] at readableAddChunk (_stream_readable.js:269:11)
[0] at Socket.Readable.push (_stream_readable.js:224:10)
EntrainmentEntity
@Entity()
export class Entrainements extends HistoriqueEntity {
@Column()
name: string;
@ManyToMany( () => Categories, {cascade: true} )
@JoinTable()
category: Categories[];
@Column()
distance: number;
@Column()
start: number;
@Column()
comments: string;
@Column()
warmUp: string;
@Column()
cadence: string;
@ManyToOne(type => Season, season => season.name)
season: Season;
@Column()
rest: string;
@ManyToOne(type => Roles, role => role.entrainements)
role: Roles;
@ManyToMany( () => Exercices, {cascade: true} )
@JoinTable()
exercices: Exercices[];
}
ExercicesEntity:
@Entity()
export class Exercices extends HistoriqueEntity {
@Column()
name: string;
@Column()
description: string;
@ManyToOne(type => TypeExercices, typeExercices => typeExercices.exercices)
typeExercices: TypeExercices;
@ManyToMany(type => Entrainements, entrainements => entrainements.exercices)
entrainements: Entrainements[];
}
CategoriesEntity
@Entity()
export class Categories extends HistoriqueEntity {
@Column()
name: string;
@ManyToMany(type => Entrainements, entrainements => entrainements.category)
entrainements: Entrainements[];
}
EntrainementControlleur
@Put(':id/update')
async update(@Param('id') id, @Body() entrainementsData: Entrainements): Promise<UpdateResult> {
entrainementsData.id = Number(id);
return this.service.updateTraining(entrainementsData);
}
EntrainementsService
async updateTraining(entrainement: Entrainements): Promise<UpdateResult> {
return await this.entrainementsRepository.update(entrainement.id, entrainement);
}
答案 0 :(得分:0)
您应该定义相反的绑定:
UserControl