I am doing a lot of research and experiment to use an enum array in my entity.
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)
}
}
Unfortunately it gives me this error.
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
How can I solve this? I can't get what's wrong on my decorator options.
leaving this here for anyone visiting this post for the same issue as me
export enum StringEnum {
ADMIN = "a",
EDITOR = "e",
MODERATOR = "m",
GHOST = "g"
}
@Column({
type: "enum",
enum: StringEnum,
array: true,
default: [StringEnum.ADMIN]
})
stringEnums: StringEnum[];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With