mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: convert the join table ID to the referenceColumn ID type (#9887)
* fix: Convert the join table ID to the referenceColumn ID type * test: add auto-increment-id-as-string test * style: format auto-increment-id-as-string test
This commit is contained in:
parent
938f94bded
commit
9460296147
@ -497,7 +497,7 @@ export class RawSqlResultsToEntityTransformer {
|
||||
column.referencedColumn!.databaseName,
|
||||
)
|
||||
],
|
||||
column,
|
||||
column.referencedColumn!,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
import "reflect-metadata"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils"
|
||||
import { DataSource } from "../../../src/data-source/DataSource"
|
||||
import { User } from "./entity/User"
|
||||
import { Role } from "./entity/Role"
|
||||
|
||||
describe("other issues > auto-increment id as string", () => {
|
||||
let connections: DataSource[]
|
||||
before(
|
||||
async () =>
|
||||
(connections = await createTestingConnections({
|
||||
entities: [__dirname + "/entity/*{.js,.ts}"],
|
||||
})),
|
||||
)
|
||||
beforeEach(() => reloadTestingDatabases(connections))
|
||||
after(() => closeTestingConnections(connections))
|
||||
|
||||
it("should relationIds exist", () =>
|
||||
Promise.all(
|
||||
connections.map(async function (connection) {
|
||||
const role1 = new Role()
|
||||
role1.roleName = "#role 1"
|
||||
const role2 = new Role()
|
||||
role2.roleName = "#role 2"
|
||||
|
||||
const user = new User()
|
||||
user.userName = "#user 1"
|
||||
user.roles = [
|
||||
await connection.manager.save(role1),
|
||||
await connection.manager.save(role2),
|
||||
]
|
||||
|
||||
const user2 = await connection.manager.save(user)
|
||||
|
||||
const user3 = await connection.manager.findOne(User, {
|
||||
where: {
|
||||
userId: user2.userId,
|
||||
},
|
||||
loadRelationIds: true,
|
||||
})
|
||||
user3!.roles.length.should.be.equal(2)
|
||||
}),
|
||||
))
|
||||
})
|
||||
24
test/other-issues/auto-increment-id-as-string/entity/Role.ts
Normal file
24
test/other-issues/auto-increment-id-as-string/entity/Role.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Column } from "../../../../src/decorator/columns/Column"
|
||||
import { Entity } from "../../../../src/decorator/entity/Entity"
|
||||
|
||||
@Entity()
|
||||
export class Role {
|
||||
@Column({
|
||||
name: "role_id",
|
||||
primary: true,
|
||||
type: "int",
|
||||
generated: "increment",
|
||||
transformer: {
|
||||
to(value: object) {
|
||||
return value?.toString()
|
||||
},
|
||||
from(value: object) {
|
||||
return value?.toString()
|
||||
},
|
||||
},
|
||||
})
|
||||
roleId: string
|
||||
|
||||
@Column({ name: "role_name" })
|
||||
roleName: string
|
||||
}
|
||||
40
test/other-issues/auto-increment-id-as-string/entity/User.ts
Normal file
40
test/other-issues/auto-increment-id-as-string/entity/User.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { JoinTable, ManyToMany } from "../../../../src"
|
||||
import { Column } from "../../../../src/decorator/columns/Column"
|
||||
import { Entity } from "../../../../src/decorator/entity/Entity"
|
||||
import { Role } from "./Role"
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
@Column({
|
||||
name: "user_id",
|
||||
primary: true,
|
||||
type: "int",
|
||||
generated: "increment",
|
||||
transformer: {
|
||||
to(value: object) {
|
||||
return value?.toString()
|
||||
},
|
||||
from(value: object) {
|
||||
return value?.toString()
|
||||
},
|
||||
},
|
||||
})
|
||||
userId: string
|
||||
|
||||
@Column({ name: "user_name" })
|
||||
userName: string
|
||||
|
||||
@ManyToMany((type) => Role)
|
||||
@JoinTable({
|
||||
name: "user_role",
|
||||
joinColumn: {
|
||||
name: "user_id",
|
||||
referencedColumnName: "userId",
|
||||
},
|
||||
inverseJoinColumn: {
|
||||
name: "role_id",
|
||||
referencedColumnName: "roleId",
|
||||
},
|
||||
})
|
||||
roles: Role[]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user