dyna-record
    Preparing search index...

    Type Alias CreateCondition<T>

    CreateCondition: [keyof CreateConditionKeys<T>] extends [never]
        ? Record<string, never>
        : CreateConditionKeys<T>

    The condition a create accepts: 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:

    • BelongsTo relationships backed by a foreign key declared with its target type, taking a TargetCondition on the parent row.
    • Other typed foreign keys — the child side of a one-way HasMany, or a standalone foreign key — taking a ForeignKeyTargetGuard.

    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 target on a bare ForeignKey presents UntypedForeignKeyTargetError. The guarded foreign key must be set in the attributes being created: a guard on one the create leaves unset is a FilterError.

    Type Parameters

    • T extends default

      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" } }
    }
    }
    );