Skip to content

Commit 8e0d817

Browse files
authored
fix: use an empty string enum as the type of a primary key column (#6063)
Closes: #3874
1 parent 08cc076 commit 8e0d817

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts‎

Lines changed: 0 additions & 1 deletion
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) {
Lines changed: 16 additions & 0 deletions
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+
}
Lines changed: 30 additions & 0 deletions
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+
});

0 commit comments

Comments
 (0)