deepkit-framework
deepkit-framework copied to clipboard
[BUG] ORM serialization problem with table connection.
Desc
JSON that appears when I perform an associated query of user and role Stringify() problem.
Code
RoleEntity.ts
import { BackReference, entity, Index, MinLength, Unique } from "@deepkit/type";
import { Common } from "./CommonEntity";
import { User } from "./UserEntity";
import { UserJoinRole } from "./UserJoinRoleEntity";
@entity.name("role")
export class Role extends Common {
name!: string & Unique & MinLength<1>;
note: string = ""; // 备注
actions: string[] = []; // 权限
users?: User[] & BackReference<{ via: typeof UserJoinRole }>;
constructor() {
super();
}
}
UserEntity.ts
import { BackReference, entity, MinLength, Unique } from "@deepkit/type";
import { Common } from "./CommonEntity";
import { Role } from "./RoleEntity";
import { UserJoinRole } from "./UserJoinRoleEntity";
@entity.name("user")
export class User extends Common {
username!: string & Unique & MinLength<4>;
password!: string & MinLength<4>;
name!: string & Unique & MinLength<1>;
roles?: Role[] & BackReference<{ via: typeof UserJoinRole }>;
constructor() {
super();
}
}
UserJoinRoleEntity.ts
import { entity, Reference } from "@deepkit/type";
import { User } from "@app/orm/entities/UserEntity";
import { Common } from "./CommonEntity";
import { Role } from "./RoleEntity";
@entity.name("user_join_role")
export class UserJoinRole extends Common {
constructor(public user: User & Reference, public role: Role & Reference) {
super();
}
}
Please check this warehouse for details https://github.com/WumaCoder/deepkit-template/tree/issue/orm-stringify-bug
Error
2022-05-03T11:00:55.150Z [ERROR] HTTP kernel request failed Error: Reference Role.users was not populated. Use joinWith(), useJoinWith(), etc to populate the reference.
at Role.get [as users] (/Users/wmc/workspace/deepkit-template/node_modules/.pnpm/@[email protected]_1917e6869355259966282aa5b39cebd0/node_modules/@deepkit/orm/src/formatter.ts:93:27)
at JSON.stringify (<anonymous>)
at HttpResultFormatter.handleUnknown (/Users/wmc/workspace/deepkit-template/node_modules/.pnpm/@[email protected]_1dd46d10d77d840c9f0659f5c831d264/node_modules/@deepkit/http/src/http.ts:390:35)
at HttpResultFormatter.handle (/Users/wmc/workspace/deepkit-template/node_modules/.pnpm/@[email protected]_1dd46d10d77d840c9f0659f5c831d264/node_modules/@deepkit/http/src/http.ts:444:18)
at HttpListener.onResponse (/Users/wmc/workspace/deepkit-template/node_modules/.pnpm/@[email protected]_1dd46d10d77d840c9f0659f5c831d264/node_modules/@deepkit/http/src/http.ts:702:30)
at self (eval at buildAsync (/Users/wmc/workspace/deepkit-template/node_modules/.pnpm/@[email protected]/node_modules/@deepkit/core/src/compiler.ts:111:20), <anonymous>:270:52)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async HttpKernel.handleRequest (/Users/wmc/workspace/deepkit-template/node_modules/.pnpm/@[email protected]_1dd46d10d77d840c9f0659f5c831d264/node_modules/@deepkit/http/src/kernel.ts:40:17)
Reproduction
-
pnpm i && pnpm dev && pnpm start init - request
GET /userapi