Skip to content

Commit

Permalink
fix: use an empty string enum as the type of a primary key column (#6063
Browse files Browse the repository at this point in the history
)

Closes: #3874
  • Loading branch information
BTOdell committed May 15, 2020
1 parent 08cc076 commit 8e0d817
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Expand Up @@ -72,7 +72,6 @@ export class RawSqlResultsToEntityTransformer {

return keyValue;
}).join("_"); // todo: check partial
if (!id) return;

const items = map.get(id);
if (!items) {
Expand Down
16 changes: 16 additions & 0 deletions test/github-issues/3874/entity/Settings.ts
@@ -0,0 +1,16 @@
import {Entity, Column, PrimaryColumn} from "../../../../src";

enum Singleton {
EMPTY = ""
}

@Entity()
export class Settings {

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

@Column()
value!: string;

}
30 changes: 30 additions & 0 deletions test/github-issues/3874/issue-3874.ts
@@ -0,0 +1,30 @@
import "reflect-metadata";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Settings} from "./entity/Settings";
import {expect} from "chai";

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

let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [Settings],
enabledDrivers: ["mysql", "mariadb"],
schemaCreate: true,
dropSchema: true,
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));

it("should reload entity", () => Promise.all(connections.map(async connection => {
// Create initial settings row
const newSettings = new Settings();
newSettings.value = "string";
await connection.manager.save(newSettings);
// Attempt to read settings back
const foundSettings = await connection.manager.findOne(Settings);
expect(foundSettings).to.be.an.instanceOf(Settings);
expect(foundSettings != null ? foundSettings.value : null).to.equal("string");
})));

});

0 comments on commit 8e0d817

Please sign in to comment.