mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
tests for #401
This commit is contained in:
parent
4b933867c4
commit
2a64aaf8b6
@ -615,7 +615,7 @@ export class MysqlQueryRunner implements QueryRunner {
|
||||
await this.startTransaction();
|
||||
try {
|
||||
const disableForeignKeysCheckQuery = `SET FOREIGN_KEY_CHECKS = 0;`;
|
||||
const dropTablesQuery = `SELECT concat('DROP TABLE IF EXISTS ', table_name, ';') AS query FROM information_schema.tables WHERE table_schema = '${this.dbName}'`;
|
||||
const dropTablesQuery = `SELECT concat('DROP TABLE IF EXISTS \`', table_name, '\`;') AS query FROM information_schema.tables WHERE table_schema = '${this.dbName}'`;
|
||||
const enableForeignKeysCheckQuery = `SET FOREIGN_KEY_CHECKS = 1;`;
|
||||
|
||||
await this.query(disableForeignKeysCheckQuery);
|
||||
|
||||
@ -628,7 +628,7 @@ AND cons.constraint_name = cols.constraint_name AND cons.owner = cols.owner ORDE
|
||||
await this.startTransaction();
|
||||
try {
|
||||
const disableForeignKeysCheckQuery = `SET FOREIGN_KEY_CHECKS = 0;`;
|
||||
const dropTablesQuery = `SELECT concat('DROP TABLE IF EXISTS ', table_name, ';') AS query FROM information_schema.tables WHERE table_schema = '${this.dbName}'`;
|
||||
const dropTablesQuery = `SELECT concat('DROP TABLE IF EXISTS "', table_name, '";') AS query FROM information_schema.tables WHERE table_schema = '${this.dbName}'`;
|
||||
const enableForeignKeysCheckQuery = `SET FOREIGN_KEY_CHECKS = 1;`;
|
||||
|
||||
await this.query(disableForeignKeysCheckQuery);
|
||||
|
||||
14
test/github-issues/401/entity/Group.ts
Normal file
14
test/github-issues/401/entity/Group.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import {Entity} from "../../../../src/decorator/entity/Entity";
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn";
|
||||
|
||||
@Entity()
|
||||
export class Group {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
}
|
||||
16
test/github-issues/401/entity/Player.ts
Normal file
16
test/github-issues/401/entity/Player.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import {Entity} from "../../../../src/decorator/entity/Entity";
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
import {PrimaryColumn} from "../../../../src/decorator/columns/PrimaryColumn";
|
||||
import {ManyToOne} from "../../../../src/decorator/relations/ManyToOne";
|
||||
import {Group} from "./Group";
|
||||
|
||||
@Entity()
|
||||
export class Player {
|
||||
|
||||
@PrimaryColumn()
|
||||
email: string;
|
||||
|
||||
@ManyToOne(type => Group)
|
||||
group: Group;
|
||||
|
||||
}
|
||||
46
test/github-issues/401/issue-401.ts
Normal file
46
test/github-issues/401/issue-401.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import "reflect-metadata";
|
||||
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
|
||||
import {Connection} from "../../../src/connection/Connection";
|
||||
import {expect} from "chai";
|
||||
import {Player} from "./entity/Player";
|
||||
import {Group} from "./entity/Group";
|
||||
|
||||
describe.only("github issues > #401 special keywords should be escaped in join queries", () => {
|
||||
|
||||
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 escape 'group' keyword properly", () => Promise.all(connections.map(async connection => {
|
||||
|
||||
const group = new Group();
|
||||
group.name = "about players";
|
||||
await connection.manager.save(group);
|
||||
|
||||
const player = new Player();
|
||||
player.email = "player@gmail.com";
|
||||
player.group = group;
|
||||
await connection.manager.save(player);
|
||||
|
||||
const loadedPlayer = await connection
|
||||
.getRepository(Player)
|
||||
.createQueryBuilder("player")
|
||||
.leftJoinAndSelect("player.group", "group")
|
||||
.where("player.email = :email", { email: "player@gmail.com" })
|
||||
.getOne();
|
||||
|
||||
expect(loadedPlayer).to.be.eql({
|
||||
email: "player@gmail.com",
|
||||
group: {
|
||||
id: 1,
|
||||
name: "about players"
|
||||
}
|
||||
});
|
||||
})));
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user