【发布时间】:2022-02-15 21:12:04
【问题描述】:
使用 TypeORM 并出现此错误:
ValidationError: Using global EntityManager instance methods for context specific actions is disallowed.
If you need to work with the global instance's identity map, use `allowGlobalContext` configuration option or `fork()` instead
它对应的代码如下:
import { MikroORM } from "@mikro-orm/core";
import { __prod__ } from "./constants";
import { Post } from "./entities/Post";
import mikroConfig from "./mikro-orm.config";
const main = async () => {
const orm = await MikroORM.init(mikroConfig);
const post = orm.em.create(Post, {
title: "my first post",
});
await orm.em.persistAndFlush(post);
await orm.em.nativeInsert(Post, { title: "my first post 2" });
};
main().catch((error) => {
console.error(error);
});
我不确定在哪里需要使用 .fork() 方法
【问题讨论】:
-
感谢您提出这个问题。我也是通过在 YouTube 上观看 Ben Awad 的 Fullstack React GraphQL TypeScript 教程来到这里的。
标签: node.js typescript graphql typeorm