-
I have two mongo entities: export class ParentEntity {
@PrimaryKey()
_id!: ObjectId;
@SerializedPrimaryKey()
id!: string;
@Property()
childrenIds!: string[] | ObjectId[]; // whatever works
} export class ChildEntity {
@PrimaryKey()
_id!: ObjectId;
@SerializedPrimaryKey()
id!: string;
@Property()
parentId!: string | ObjectId; // whatever works
} I want them to verify each other ids whenever they are updated. Whenever child entity's parentId is updated, it checks for the fact that the parent exists. Whenever parent's childrenIds is updated, it checks that all provided ids refer to existing children. Is this possible to do natively through entity declaration? Or do I need to manually verify entity existence before each update? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
No, the ORM does not do such checks, with SQL drivers this is a native feature of the db engines (called referential integrity - and you need actual relations for this, not just scalar properties), not of the ORM. If you want this, you need to implement it yourself in your app code. |
Beta Was this translation helpful? Give feedback.
No, the ORM does not do such checks, with SQL drivers this is a native feature of the db engines (called referential integrity - and you need actual relations for this, not just scalar properties), not of the ORM. If you want this, you need to implement it yourself in your app code.