Skip to main content
Version: Next

abstractBaseEntity

Index

Constructors

constructor

Methods

assign

  • assign<Entity, Naked, Convert, Data>(data, options): MergeSelected<Entity, Naked, keyof Data & string>

getSchema

  • getSchema(): undefined | string
  • Returns undefined | string

init

  • init<Entity, Hint, Fields, Excludes>(options): Promise<null | Loaded<Entity, Hint, Fields, Excludes>>
  • Parameters

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

isInitialized

  • isInitialized(): boolean
  • Returns boolean

populate

  • populate<Entity, Hint, Fields>(populate, options): Promise<Loaded<Entity, Hint>>

populated

  • populated(populated): void
  • Parameters

    • populated: boolean = true

    Returns void

serialize

  • serialize<Entity, Naked, Hint, Exclude>(options): SerializeDTO<Naked, Hint, Exclude, never>

setSchema

  • setSchema(schema): void
  • Parameters

    • optionalschema: string

    Returns void

toObject

  • 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>

toPOJO

toReference