fix: use an empty string enum as the type of a primary key column (#6… · typeorm/typeorm@8e0d817

File tree

3 files changed

lines changed

  • src/query-builder/transformer

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -72,7 +72,6 @@ export class RawSqlResultsToEntityTransformer {

7272
7373

return keyValue;

7474

}).join("_"); // todo: check partial

75-

if (!id) return;

7675
7776

const items = map.get(id);

7877

if (!items) {

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,16 @@

1+

import {Entity, Column, PrimaryColumn} from "../../../../src";

2+
3+

enum Singleton {

4+

EMPTY = ""

5+

}

6+
7+

@Entity()

8+

export class Settings {

9+
10+

@PrimaryColumn()

11+

readonly singleton: Singleton = Singleton.EMPTY;

12+
13+

@Column()

14+

value!: string;

15+
16+

}

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,30 @@

1+

import "reflect-metadata";

2+

import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";

3+

import {Connection} from "../../../src/connection/Connection";

4+

import {Settings} from "./entity/Settings";

5+

import {expect} from "chai";

6+
7+

describe("github issues > #3874 Using an (empty string) enum as the type of a primary key column", () => {

8+
9+

let connections: Connection[];

10+

before(async () => connections = await createTestingConnections({

11+

entities: [Settings],

12+

enabledDrivers: ["mysql", "mariadb"],

13+

schemaCreate: true,

14+

dropSchema: true,

15+

}));

16+

beforeEach(() => reloadTestingDatabases(connections));

17+

after(() => closeTestingConnections(connections));

18+
19+

it("should reload entity", () => Promise.all(connections.map(async connection => {

20+

// Create initial settings row

21+

const newSettings = new Settings();

22+

newSettings.value = "string";

23+

await connection.manager.save(newSettings);

24+

// Attempt to read settings back

25+

const foundSettings = await connection.manager.findOne(Settings);

26+

expect(foundSettings).to.be.an.instanceOf(Settings);

27+

expect(foundSettings != null ? foundSettings.value : null).to.equal("string");

28+

})));

29+
30+

});