Member Junction
    Preparing search index...

    Class EmbeddedRecord<T>

    Internal companion for one owner-held 1:1 peer.

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    ForeignKeyField: string
    Name: string

    Stable identifier for this companion, unique within its owning entity.

    This is the wire key: it appears in serialized payloads and is how the receiving tier finds the companion to deserialize into. Treat it as a published contract — renaming it breaks in-flight payloads and any persisted snapshot that captured them.

    Owner: BaseEntity

    The entity this companion is attached to. Set by BaseEntity.RegisterCompanion.

    RelatedEntityName: string

    Accessors

    • get Dirty(): boolean

      Whether this companion holds unsaved changes.

      Rolled up into BaseEntity.Dirty, which is what makes a save actually happen when only the companion changed. Before companions existed, a clean parent with three new children returned early from Save() and silently persisted nothing.

      Returns boolean

      True when saving would produce work.

    Methods

    • Contributes this companion's work to the owner's save plan.

      Called after the owner's own node has been added, so implementations may assume the parent node exists and order their nodes relative to it. Add nothing when there is no work — an empty contribution keeps the save on the fast single-row path.

      Parameters

      • plan: EntitySavePlan

        The plan being assembled for this unit of work.

      • Optionaloptions: EntitySaveOptions

        The caller's save options. Implementations that decide what counts as work (skipping clean children, most importantly) must honor flags such as IgnoreDirtyState that demand a full write-out.

      Returns void

    • Constructs the related entity instance without NewRecord / Load. Called from BaseEntity.InitializeEmbeddedRecords during GetEntityObject.

      Parameters

      • visited: Set<string>

        Entity names already being constructed, for cycle detection.

      Returns Promise<void>

    • Populates this companion from the database, when it is configured to load eagerly.

      Called by BaseEntity.Load() after the record's own fields are populated. Never called from LoadFromData() — that is the row-materialization path for RunView(ResultType:'entity_object'), so loading children there turns one view into an N+1 storm. Set-oriented eager loading is handled by RunView's batched child loading instead.

      Parameters

      • visited: Set<string> = ...

        EntityName:PK tokens already on this load walk. Embedded records use it to fail a self-parented / cyclic inherit instead of recursing until the stack dies.

      Returns Promise<void>

    • Synchronous, in-memory validation contributed by this companion.

      Runs as part of the owner's Validate(), before any write, over the companion's complete state — including pending removals. That ordering is what lets cross-child invariants such as "debits must equal credits" be enforced correctly rather than after half the graph has landed.

      Push errors onto result.Errors and set result.Success = false to fail the save.

      Parameters

      Returns void

    • Asynchronous validation contributed by this companion — anything that needs a round trip.

      Parameters

      Returns Promise<void>

      Unlike an entity's own ValidateAsync(), this is not governed by BaseEntity.DefaultSkipAsyncValidation. That flag exists so an entity can opt out of its own expensive async rules; applying it to companions silently skipped cross-child invariants, which is how OrderEntityServer.ValidateAsync came to be dead code on every save. Companion validation runs whenever the companion is dirty.