Skip to content

Enum not resolved if it is from an external file #6540

@Ripper346

Description

@Ripper346

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I am using nestjs, I have defined an enum in an entity and used there. I needed to use it also in another entity, however, using an import typeorm seems to not resolve it.

In my file order.entity.ts I define

export enum OrderStatus {
    placed = "placed",
    paid = "paid",
    confirmed = "confirmed",
    shipped = "shipped",
    completed = "completed",
    cancelled = "cancelled"
}

@Entity()
export class Order extends BaseEntity {
    @PrimaryGeneratedColumn("uuid")
    id: string

    @IsNotEmpty()
    @Column({ type: "enum", enum: OrderStatus })
    status: OrderStatus
}

and in the issue entity order-product.entity.ts I write:

import { OrderStatus } from "./order.entity";

@Entity()
export class OrderProduct extends BaseEntity {
    @PrimaryGeneratedColumn("increment")
    id: number

    @IsNotEmpty()
    @Column({ type: "enum", enum: OrderStatus })
    status: OrderStatus
}

The resulting query is CREATE TABLE `order_product` (`id` int NOT NULL AUTO_INCREMENT, `status` enum NOT NULL, PRIMARY KEY (`id`)) producing an sql error as the enum is not defined.
The error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOT NULL, PRIMARY KEY (`id`))' at line 1

Defining the enum also inside the orderProduct entity file the enum is resolved and the query is executed correctly.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions