Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use an empty string enum as the type of a primary key column #6063

Merged
merged 1 commit into from May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");
})));

});