Skip to content

Using an (empty string) enum as the type of a primary key column #3874

@BTOdell

Description

@BTOdell

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
[x] 0.2.15

Steps to reproduce or a small repository showing the problem:

import {BaseEntity, Entity, PrimaryColumn, Column} from "typeorm";

enum Singleton {
    EMPTY = ""
}

/**
 * Global application settings.
 */
@Entity("settings")
export class Settings extends BaseEntity {

    @PrimaryColumn()
    readonly singleton: Singleton = Singleton.EMPTY;

    @Column()
    value!: string;

}

I have a "settings" table in my database that holds global application settings (one setting per column). In non-TypeORM projects, I've always used an enum primary key to enforce the existence of only one row. But TypeORM is not loading anything when I run:

Settings.find();

The array is empty (despite having a fully populated row in the database).

If I change the entity definition to:

import {BaseEntity, Entity, PrimaryColumn, Column} from "typeorm";

/**
 * Global application settings.
 */
@Entity("settings")
export class Settings extends BaseEntity {

    @PrimaryColumn()
    readonly singleton: number = 0;

    @Column()
    value!: string;

}

then it starts working (after updating the database schema).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions