abstractLoadableBaseEntity
Hierarchy
- LoadableBaseEntityBase
- LoadableBaseEntity
Index
Constructors
constructor
Returns LoadableBaseEntity
Methods
inheritedassign
Assigns the given data to this entity, updating its properties and relations.
Parameters
data: Data & IsSubset<EntityData<Naked>, Data>
options: AssignOptions<Convert> = {}
Returns MergeSelected<Entity, Naked, keyof Data & string>
inheritedgetSchema
Returns the database schema this entity belongs to.
Returns undefined | string
inheritedinit
Initializes (refreshes) the entity by reloading it from the database. Returns null if not found.
Parameters
optionaloptions: FindOneOptions<Entity, Hint, Fields, Excludes>
Returns Promise<null | Loaded<Entity, Hint, Fields, Excludes>>
inheritedisInitialized
Returns whether the entity has been fully loaded from the database.
Returns boolean
inheritedload
Ensures this entity is loaded (without reloading it if it already is). Returns the entity, or
nullif it was not found in the database (e.g. it was deleted in the meantime, or active filters disallow loading it). UseloadOrFail()if you want an error to be thrown in such a case.Parameters
optionaloptions: LoadReferenceOptions<Entity, Hint, Fields, Excludes>
Returns Promise<null | Loaded<Entity, Hint, Fields, Excludes>>
inheritedloadOrFail
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
optionaloptions: LoadReferenceOrFailOptions<Entity, Hint, Fields, Excludes>
Returns Promise<Loaded<Entity, Hint, Fields, Excludes>>
inheritedpopulate
Loads the specified relations on this entity.
Parameters
populate: false | AutoPath<Entity, Hint, ALL, 9>[]
options: EntityLoaderOptions<Entity, Fields, never> = {}
Returns Promise<Loaded<Entity, Hint>>
inheritedpopulated
Marks the entity as populated or not for serialization purposes.
Parameters
populated: boolean = true
Returns void
inheritedserialize
Serializes the entity with control over which relations and fields to include or exclude.
Parameters
optionaloptions: SerializeOptions<Naked, Hint, Exclude, Fields>
Returns SerializeDTO<Naked, Hint, Exclude, never, ResolveSerializeFields<Fields, ExtractFieldsHint<Entity>>, SerializeFieldsKeepPK<Fields>>
inheritedsetSchema
Sets the database schema for this entity.
Parameters
optionalschema: string
Returns void
inheritedtoObject
Converts the entity to a plain object representation.
Note on typing with
Loadedentities: When called on aLoaded<Entity, 'relation'>type, the return type will beEntityDTO<Entity>(with relations as primary keys), notEntityDTO<Loaded<Entity, 'relation'>>(with loaded relations as nested objects). This is a TypeScript limitation - thethistype resolves to the class, not theLoadedwrapper.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>>>
Convenience:
BaseEntitypre-composed with theLoadablemixin.