Skip to main content
Version: Next

abstractLoadableBaseEntity

Convenience: BaseEntity pre-composed with the Loadable mixin.

Hierarchy

  • LoadableBaseEntityBase
    • LoadableBaseEntity

Index

Constructors

constructor

Methods

inheritedassign

  • assign<Entity, Naked, Convert, Data>(data, options): MergeSelected<Entity, Naked, keyof Data & string>
  • Assigns the given data to this entity, updating its properties and relations.


    Parameters

    Returns MergeSelected<Entity, Naked, keyof Data & string>

inheritedgetSchema

  • getSchema(): undefined | string
  • Returns the database schema this entity belongs to.


    Returns undefined | string

inheritedinit

  • init<Entity, Hint, Fields, Excludes>(options): Promise<null | Loaded<Entity, Hint, Fields, Excludes>>
  • Initializes (refreshes) the entity by reloading it from the database. Returns null if not found.


    Parameters

    Returns Promise<null | Loaded<Entity, Hint, Fields, Excludes>>

inheritedisInitialized

  • isInitialized(): boolean
  • Returns whether the entity has been fully loaded from the database.


    Returns boolean

inheritedload

  • load<Entity, Hint, Fields, Excludes>(options): Promise<null | Loaded<Entity, Hint, Fields, Excludes>>
  • Ensures this entity is loaded (without reloading it if it already is). Returns the entity, or null if it was not found in the database (e.g. it was deleted in the meantime, or active filters disallow loading it). Use loadOrFail() if you want an error to be thrown in such a case.


    Parameters

    Returns Promise<null | Loaded<Entity, Hint, Fields, Excludes>>

inheritedloadOrFail

  • loadOrFail<Entity, Hint, Fields, Excludes>(options): Promise<Loaded<Entity, Hint, Fields, Excludes>>
  • Ensures this entity is loaded (without reloading it if it already is). Returns the entity, or throws an error just like em.findOneOrFail() (and respects the same config options) if it was not found.


    Parameters

    Returns Promise<Loaded<Entity, Hint, Fields, Excludes>>

inheritedpopulate

  • populate<Entity, Hint, Fields>(populate, options): Promise<Loaded<Entity, Hint>>
  • Loads the specified relations on this entity.


    Parameters

    Returns Promise<Loaded<Entity, Hint>>

inheritedpopulated

  • populated(populated): void
  • Marks the entity as populated or not for serialization purposes.


    Parameters

    • populated: boolean = true

    Returns void

inheritedserialize

  • serialize<Entity, Naked, Hint, Exclude, Fields>(options): SerializeDTO<Naked, Hint, Exclude, never, ResolveSerializeFields<Fields, ExtractFieldsHint<Entity>>, SerializeFieldsKeepPK<Fields>>
  • Serializes the entity with control over which relations and fields to include or exclude.


    Parameters

    Returns SerializeDTO<Naked, Hint, Exclude, never, ResolveSerializeFields<Fields, ExtractFieldsHint<Entity>>, SerializeFieldsKeepPK<Fields>>

inheritedsetSchema

  • setSchema(schema): void
  • Sets the database schema for this entity.


    Parameters

    • optionalschema: string

    Returns void

inheritedtoObject

  • toObject<Entity>(): EntityDTO<Entity>
  • toObject<Entity>(ignoreFields): EntityDTO<Entity>
  • toObject<Entity, Ignored>(ignoreFields): Omit<EntityDTO<Entity>, Ignored>
  • Converts the entity to a plain object representation.

    Note on typing with Loaded entities: When called on a Loaded<Entity, 'relation'> type, the return type will be EntityDTO<Entity> (with relations as primary keys), not EntityDTO<Loaded<Entity, 'relation'>> (with loaded relations as nested objects). This is a TypeScript limitation - the this type resolves to the class, not the Loaded wrapper.

    For correct typing that reflects loaded relations, use wrap():

    const result = await em.find(User, {}, { populate: ['profile'] });
    // Type: EntityDTO<User> (profile is number)
    const obj1 = result[0].toObject();
    // Type: EntityDTO<Loaded<User, 'profile'>> (profile is nested object)
    const obj2 = wrap(result[0]).toObject();

    Runtime values are correct in both cases - only the static types differ.


    Returns EntityDTO<Entity>

inheritedtoPOJO

  • Converts the entity to a plain object, including all properties regardless of serialization rules.


    Returns EntityDTO<Entity>

inheritedtoReference

  • Returns a Reference wrapper for this entity.


    Returns Reference<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>