This commit is contained in:
Umed Khudoiberdiev 2017-05-27 12:43:40 +05:00
parent bea212ecab
commit 71a10c2275
3 changed files with 55 additions and 1 deletions

View File

@ -978,7 +978,7 @@ export class QueryBuilder<Entity> {
}).join(" OR ");
} else {
const ids = rawResults.map(result => result["ids_" + metadata.primaryColumns[0].propertyName]);
const areAllNumbers = ids.map((id: any) => typeof id === "number");
const areAllNumbers = ids.every((id: any) => typeof id === "number");
if (areAllNumbers) {
// fixes #190. if all numbers then its safe to perform query without parameter
condition = `${mainAliasName}.${metadata.primaryColumns[0].propertyName} IN (${ids.join(", ")})`;

View File

@ -0,0 +1,14 @@
import {Entity} from "../../../../src/decorator/entity/Entity";
import {Column} from "../../../../src/decorator/columns/Column";
import {PrimaryColumn} from "../../../../src/decorator/columns/PrimaryColumn";
@Entity()
export class Post {
@PrimaryColumn()
id: string;
@Column()
title: string;
}

View File

@ -0,0 +1,40 @@
import "reflect-metadata";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Post} from "./entity/Post";
describe("github issues > #493 pagination should work with string primary keys", () => {
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should work perfectly with string primary keys", () => Promise.all(connections.map(async connection => {
for (let i = 0; i < 10; i++) {
const post = new Post();
post.id = "post #" + i;
post.title = "Hello Post #" + i;
await connection.manager.save(post);
}
const loadedPosts = await connection.manager
.createQueryBuilder(Post, "post")
.take(5)
.skip(0)
.getMany();
loadedPosts.length.should.be.equal(5);
loadedPosts[0]!.id.should.be.equal("post #0");
loadedPosts[1]!.id.should.be.equal("post #1");
loadedPosts[2]!.id.should.be.equal("post #2");
loadedPosts[3]!.id.should.be.equal("post #3");
loadedPosts[4]!.id.should.be.equal("post #4");
})));
});