- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不想创建用于将关系加载到其中的属性(如所有示例所示)。我唯一需要做的就是拥有一个明确的外键属性,以便迁移能够在数据库中为其创建适当的约束。与我需要的装饰器最接近的装饰器是@RelationId,但它仍然需要存在关系类的属性。
为了清楚起见,让我们以文档中的示例为例:
@Entity()
export class Post {
@ManyToOne(type => Category)
category: Category;
@RelationId((post: Post) => post.category) // it still requires the presence of the `category` proeprty
categoryId: number;
}
category
属性。我想拥有
categoryId
属性,并将其标记为
Category.Id
的外键。它看起来应该像这样:
@Entity()
export class Post {
@ForeignKey((category: Category) => category.Id) // it's a foreign key to Category.Id
categoryId: number;
}
最佳答案
也许您可以创建和编写自己的迁移并像这样使用它:
const queryRunner = connection.createQueryRunner();
await queryRunner.createTable(new Table({
name: "question",
columns: [
{
name: "id",
type: "int",
isPrimary: true
},
{
name: "name",
type: "varchar",
}
]
}), true);
await queryRunner.createTable(new Table({
name: "answer",
columns: [
{
name: "id",
type: "int",
isPrimary: true
},
{
name: "name",
type: "varchar",
},
{
name: "questionId",
isUnique: connection.driver instanceof CockroachDriver, // CockroachDB requires UNIQUE constraints on referenced columns
type: "int",
}
]
}), true);
// clear sqls in memory to avoid removing tables when down queries executed.
queryRunner.clearSqlMemory();
const foreignKey = new TableForeignKey({
columnNames: ["questionId"],
referencedColumnNames: ["id"],
referencedTableName: "question",
onDelete: "CASCADE"
});
await queryRunner.createForeignKey("answer", foreignKey);
关于foreign-keys - TypeORM:如何显式设置ForeignKey而没有用于加载关系的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55170906/
我知道 typeorm 可以创建整个 db 模式,甚至可以将数据库模式与实体定义同步(请参阅 synchronize 中的 Connection Options ) 但在生产中,我想要求 typeor
我有一个 Role Entity 和一个 Route Entity,它们是树形结构,它们是 ManyToMany 关系。 现在我想通过 RoleRepository.find({relations:
我已经设置了 logging: true当createConnection()来自 TypeORM ,在大多数情况下都可以正常工作。 但是有一种情况,我的数据字段之一来自特定的 query/mutat
在 Rails 上,每个测试用例都会创建一个 ActiveRecord 事务,它允许测试所有内容,然后将数据库恢复到原始状态,而不必删除所有表或任何可能影响播种机等的内容。 可以在 Typeorm 上
Note 与 Subject 具有多对多关系 查询它的最佳方式是什么?我喜欢编写以下内容来获取给定注释上的所有主题: const subjectRepo = connection.getRepos
我使用 UUID 作为我的实体的主键,它工作得很好。但我想删除那些破折号。 现在 ID 被保存为 8e5365f4-3d42-4274-bafc-93b97bd6e3f2 36 个字符 我想要的是 8
我一整天都在尝试将实体保存到 MySQL 数据库中,遇到了巨大的困难。我正在使用 NestJS 和 TypeORM。 teacher.entity.ts import { BeforeInsert,
我也想在前端使用我用 TypeORM 创建的实体。有没有一种干净的方法可以做到这一点?或者我应该继续这样做。 此时,我的文件结构如下所示(前端的 Angular 8): /server /enti
我想得到一个 basic setup使用 TypeORM 工作,并在设置后收到此错误。 这是一个 REPL(只需执行 yarn install && yarn db:dev 后跟 yarn db:mi
我正在尝试通过 Nest/TypeORM 构建 SAAS 产品,我需要按子域配置/更改数据库连接。 customer1.domain.com => connect to customer1 datab
如何将 TypeORM 与 Better-sqlite3 一起使用? 上官方documentation ,有一个section形式更好-sqlite3。 我已经通过 typeorm@latest 安装
操作系统:macOS Sierra v 10.12.6 我正在尝试使用 typeorm 在 Typescript 中构建一个应用程序,这是我第一次使用其中任何一个。 我使用了以下两种方法来安装 typ
有没有一种简单的方法可以使用 DataSource 在 typeORM v.0.3.6 中播种数据? typeorm-seeding 似乎使用已弃用的 Connection。 最佳答案 找到这个包裹
我正在做一门类(class),我们使用 express-node postgres 和 react(使用 typescript)和 typeORM。到目前为止一切都运行良好,但我面临 typeORM
尽管进行了大量研究和反复试验,但不幸的是,我还没有针对以下用例的完美解决方案:一个用户有多个帖子,这被正确地实现为一对多关系。我想为用户加载他的所有帖子,但不是帖子的所有属性,只有某些属性。 方法 1
我用 NestJS 和 ORM TypeORM 做一个 API 我有实体: 用户 关系类型 UserRelationshipType(带有用户和关系类型 ForeignKey) 和关系(与 userR
我有两个实体 Tag 和 Photo: // tag.entity.ts import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm
我有以下要保存的实体: @Entity('approvals') export class Approval { @PrimaryGeneratedColumn() id: string;
我有命令: .leftJoinAndSelect("permission.user", "user") .where("permissi
我是使用 typeorm 的新手,这是我第二次与 typeorm 混淆,我有以下查询: SELECT t1.a,t1.b,t2.a (SELECT TOP 1 t1.a FROM table1
我是一名优秀的程序员,十分优秀!