Skip to main content
Version: Next

Class: Collection<T, O>

core.Collection

Type parameters#

NameType
TT
OO = unknown

Hierarchy#

Constructors#

constructor#

new Collection<T, O>(owner, items?, initialized?)

Type parameters#

NameType
TT
OO = unknown

Parameters#

NameTypeDefault value
ownerOundefined
items?T[]undefined
initializedbooleantrue

Overrides#

ArrayCollection.constructor

Defined in#

packages/core/src/entity/Collection.ts:22

Properties#

owner#

Readonly owner: O & Partial<O> & { [EntityRepositoryType]?: unknown ; [PrimaryKeyType]?: unknown ; __helper?: IWrappedEntityInternal<O, keyof O, keyof O> ; __meta?: EntityMetadata<O> ; __platform?: Platform }

Inherited from#

ArrayCollection.owner

Accessors#

length#

get length(): number

Returns#

number

Defined in#

packages/core/src/entity/ArrayCollection.ts:139

Methods#

[Symbol.iterator]#

[Symbol.iterator](): IterableIterator<T>

Returns#

IterableIterator<T>

Inherited from#

ArrayCollection.[Symbol.iterator]

Defined in#

packages/core/src/entity/ArrayCollection.ts:143


add#

add(...items): void

Parameters#

NameType
...items(T | Reference<T>)[]

Returns#

void

Overrides#

ArrayCollection.add

Defined in#

packages/core/src/entity/Collection.ts:123


contains#

contains(item, check?): boolean

Parameters#

NameTypeDefault value
itemT | Reference<T>undefined
checkbooleantrue

Returns#

boolean

Overrides#

ArrayCollection.contains

Defined in#

packages/core/src/entity/Collection.ts:178


count#

count(): number

Returns#

number

Overrides#

ArrayCollection.count

Defined in#

packages/core/src/entity/Collection.ts:186


getIdentifiers#

getIdentifiers<U>(field?): U[]

Type parameters#

NameType
UU: IPrimaryKeyValue = Primary<T> & string & Primary<T> & number & Primary<T> & bigint & Primary<T> & Date & Primary<T> & { toHexString: () => string }

Parameters#

NameType
field?string

Returns#

U[]

Inherited from#

ArrayCollection.getIdentifiers

Defined in#

packages/core/src/entity/ArrayCollection.ts:53


getItems#

getItems(check?): T[]

Returns the items (the collection must be initialized)

Parameters#

NameTypeDefault value
checkbooleantrue

Returns#

T[]

Overrides#

ArrayCollection.getItems

Defined in#

packages/core/src/entity/Collection.ts:107


init#

init(options?): Promise<Collection<T, O>>

Parameters#

NameType
options?InitOptions<T>

Returns#

Promise<Collection<T, O>>

Defined in#

packages/core/src/entity/Collection.ts:208

init(populate?, where?, orderBy?): Promise<Collection<T, O>>

Parameters#

NameType
populate?string[]
where?FilterQuery<T>
orderBy?QueryOrderMap

Returns#

Promise<Collection<T, O>>

Defined in#

packages/core/src/entity/Collection.ts:209


isDirty#

isDirty(): boolean

Returns#

boolean

Defined in#

packages/core/src/entity/Collection.ts:200


isInitialized#

isInitialized(fully?): boolean

Parameters#

NameTypeDefault value
fullybooleanfalse

Returns#

boolean

Inherited from#

ArrayCollection.isInitialized

Defined in#

packages/core/src/entity/ArrayCollection.ts:131


loadCount#

loadCount(refresh?): Promise<number>

Gets the count of collection items from database instead of counting loaded items. The value is cached, use refresh = true to force reload it.

Parameters#

NameTypeDefault value
refreshbooleanfalse

Returns#

Promise<number>

Overrides#

ArrayCollection.loadCount

Defined in#

packages/core/src/entity/Collection.ts:63


loadItems#

loadItems(): Promise<T[]>

Initializes the collection and returns the items

Returns#

Promise<T[]>

Defined in#

packages/core/src/entity/Collection.ts:51


matching#

matching(options): Promise<T[]>

Parameters#

NameType
optionsMatchingOptions<T, Populate<T>>

Returns#

Promise<T[]>

Defined in#

packages/core/src/entity/Collection.ts:82


populated#

populated(populated?): void

Parameters#

NameTypeDefault value
populatedbooleantrue

Returns#

void

Defined in#

packages/core/src/entity/Collection.ts:195


remove#

remove(...items): void

Parameters#

NameType
...items(T | Reference<T>)[]

Returns#

void

Overrides#

ArrayCollection.remove

Defined in#

packages/core/src/entity/Collection.ts:166


removeAll#

removeAll(): void

Returns#

void

Overrides#

ArrayCollection.removeAll

Defined in#

packages/core/src/entity/Collection.ts:154


set#

set(items): void

Parameters#

NameType
items(T | Reference<T>)[]

Returns#

void

Overrides#

ArrayCollection.set

Defined in#

packages/core/src/entity/Collection.ts:130


setDirty#

setDirty(dirty?): void

Parameters#

NameTypeDefault value
dirtybooleantrue

Returns#

void

Defined in#

packages/core/src/entity/Collection.ts:204


shouldPopulate#

shouldPopulate(): boolean

Returns#

boolean

Defined in#

packages/core/src/entity/Collection.ts:191


toArray#

toArray(): Dictionary<any>[]

Returns#

Dictionary<any>[]

Inherited from#

ArrayCollection.toArray

Defined in#

packages/core/src/entity/ArrayCollection.ts:38


toJSON#

toJSON(): Dictionary<any>[]

Returns#

Dictionary<any>[]

Overrides#

ArrayCollection.toJSON

Defined in#

packages/core/src/entity/Collection.ts:115


create#

Static create<T, O>(owner, prop, items, initialized): Collection<T, O>

Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)

Type parameters#

NameType
TT
OO = any

Parameters#

NameType
ownerO
propkeyof O
itemsundefined | T[]
initializedboolean

Returns#

Collection<T, O>

Defined in#

packages/core/src/entity/Collection.ts:37