mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixes #493
This commit is contained in:
parent
bea212ecab
commit
71a10c2275
@ -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(", ")})`;
|
||||
|
||||
14
test/github-issues/493/entity/Post.ts
Normal file
14
test/github-issues/493/entity/Post.ts
Normal 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;
|
||||
|
||||
}
|
||||
40
test/github-issues/493/issue-493.ts
Normal file
40
test/github-issues/493/issue-493.ts
Normal 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");
|
||||
})));
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user