EntityForeignKeyMetadataOptions
Defined in: packages/rxdb/src/entity/property-types.interface.ts:541
实体级外键约束。
Remarks
关系元数据负责单列外键;跨列业务不变量用本配置声明。properties 与
mappedProperties 按位置一一对应,引用端必须有匹配的唯一索引。
Extends
Properties
mappedEntity
mappedEntity: Capitalize<string>;
Defined in: packages/rxdb/src/entity/property-types.interface.ts:547
被引用实体。
mappedNamespace?
optional mappedNamespace?: Lowercase<string>;
Defined in: packages/rxdb/src/entity/property-types.interface.ts:549
被引用实体命名空间,默认继承当前实体命名空间。
mappedProperties
mappedProperties: [string, ...string[]];
Defined in: packages/rxdb/src/entity/property-types.interface.ts:551
被引用实体的属性或关系 ID 字段。
name
name: Uncapitalize<string>;
Defined in: packages/rxdb/src/entity/property-types.interface.ts:543
约束名。
onDelete?
optional onDelete?:
| "NO ACTION"
| "RESTRICT"
| "CASCADE"
| "SET NULL"
| "SET DEFAULT"
| OnDeleteAction;
Defined in: packages/rxdb/src/entity/relation-types.interface.ts:182
删除时的级联行为 定义删除父表记录时如何处理子表的外键
Example
// 删除用户时级联删除订单
onDelete: OnDeleteAction.CASCADE
// 删除分类时将产品的分类ID设为NULL
onDelete: OnDeleteAction.SET_NULL
// 如果有订单则不允许删除用户
onDelete: OnDeleteAction.RESTRICT
Default
根据关系类型自动推断
Inherited from
onUpdate?
optional onUpdate?:
| "NO ACTION"
| "RESTRICT"
| "CASCADE"
| "SET NULL"
| "SET DEFAULT"
| OnUpdateAction;
Defined in: packages/rxdb/src/entity/relation-types.interface.ts:205
更新时的级联行为 定义更新父表主键时如何处理子表的外键
Example
// 更新用户ID时级联更新订单的user_id
onUpdate: OnUpdateAction.CASCADE
// 不允许更新主键(推荐)
onUpdate: OnUpdateAction.RESTRICT
Default
OnUpdateAction.RESTRICT(推荐不更新主键)
Inherited from
properties
properties: [string, ...string[]];
Defined in: packages/rxdb/src/entity/property-types.interface.ts:545
当前实体的属性或关系 ID 字段。