首页 > 解决方案 > 如何在 TypeOrm 实体中添加枚举数组?

问题描述

我正在进行大量研究和实验以在我的实体中使用枚举数组。

import { Program } from '../../program/entities/program.entity'
import {
  Column,
  Entity,
  JoinTable,
  ManyToMany,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm'
import { Exercise } from '../../exercise/entities/exercise.entity'
import { WeekDays } from '../types/week-days.enum'

@Entity()
export class Workout {
  // [...]

  @Column({
    type: 'enum',
    enum: WeekDays,
    default: [],
    array: true,
  })
  scheduledDays?: WeekDays[]

  constructor(partial: Partial<Workout> | {} = {}) {
    Object.assign(this, partial)
  }
}

不幸的是,它给了我这个错误。

QueryFailedError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'array ('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sund' at line 1

我该如何解决这个问题?我无法理解我的装饰器选项有什么问题。

标签: arraystypescriptenumsentitytypeorm

解决方案


推荐阅读