The entity being created.
// Create an Order only for a Customer named Jane
const condition: CreateCondition<Order> = { customer: { name: "Jane" } };
// Place an Order only for an active Customer at an open Store
await Order.create(
{
orderDate: new Date("2026-10-06"),
total: 40,
status: "pending",
customerId: "customer-1",
storeId: "store-1"
},
{
condition: {
customer: { status: "active" },
storeId: { target: { status: "open" } }
}
}
);
The condition a
createaccepts: guards on the rows the new entity references. The write happens only if every guard holds, checked in the same transaction as the write.Create already requires the entity's own row to be absent, so a condition on the new row's attributes could never hold, and none is offered. A new entity has no HasOne child, HasMany children or link partners yet, so the keys are limited to:
An entity with neither, such as one whose only relationships are HasMany, takes only an empty condition. Its key set would otherwise be the empty object type
{}, which an object literal is never checked against for excess properties, so any key would be accepted.A single-valued relationship that is not such a BelongsTo presents CreateRelationshipConditionError, and a
targeton a bareForeignKeypresents UntypedForeignKeyTargetError. The guarded foreign key must be set in the attributes being created: a guard on one the create leaves unset is aFilterError.