Skip to main content
Version: 4.5

Class: Collection<T, O>#

core.Collection

Type parameters#

NameDefault
T-
Ounknown

Hierarchy#

Constructors#

constructor#

+ new Collection<T, O>(owner: O, items?: T[], initialized?: boolean): Collection<T, O>

Type parameters:#

NameDefault
T-
Ounknown

Parameters:#

NameTypeDefault value
ownerO-
items?T[]-
initializedbooleantrue

Returns: Collection<T, O>

Overrides: ArrayCollection

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

Properties#

_count#

Protected Optional _count: number

Inherited from: ArrayCollection._count

Defined in: packages/core/src/entity/ArrayCollection.ts:13


_lazyInitialized#

Private _lazyInitialized: boolean= false

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


_populated#

Private _populated: boolean= false

Defined in: packages/core/src/entity/Collection.ts:21


dirty#

Private dirty: boolean= false

Defined in: packages/core/src/entity/Collection.ts:19


initialized#

Protected initialized: boolean= true

Inherited from: ArrayCollection.initialized

Defined in: packages/core/src/entity/ArrayCollection.ts:12


items#

Protected Readonly items: Set<T>

Inherited from: ArrayCollection.items

Defined in: packages/core/src/entity/ArrayCollection.ts:11


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


readonly#

Private Optional readonly: boolean

Defined in: packages/core/src/entity/Collection.ts:20


snapshot#

Private snapshot: undefined | T[]

Defined in: packages/core/src/entity/Collection.ts:18

Accessors#

length#

• get length(): number

Returns: number

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


property#

• get property(): EntityProperty<T>

internal

Returns: EntityProperty<T>

Defined in: packages/core/src/entity/ArrayCollection.ts:152

Methods#

[Symbol.iterator]#

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

Returns: IterableIterator<T>

Inherited from: ArrayCollection

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


add#

add(...items: (T | Reference<T>)[]): void

Parameters:#

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

Returns: void

Overrides: ArrayCollection

Defined in: packages/core/src/entity/Collection.ts:118


cancelOrphanRemoval#

PrivatecancelOrphanRemoval(items: T[]): void

Parameters:#

NameType
itemsT[]

Returns: void

Defined in: packages/core/src/entity/Collection.ts:332


checkInitialized#

PrivatecheckInitialized(): void

Returns: void

Defined in: packages/core/src/entity/Collection.ts:317


contains#

contains(item: T | Reference<T>, check?: boolean): boolean

Parameters:#

NameTypeDefault value
itemT | Reference<T>-
checkbooleantrue

Returns: boolean

Overrides: ArrayCollection

Defined in: packages/core/src/entity/Collection.ts:161


count#

count(): number

Returns: number

Overrides: ArrayCollection

Defined in: packages/core/src/entity/Collection.ts:169


createCondition#

PrivatecreateCondition<T>(cond?: FilterQuery<T>): FilterQuery<T>

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameType
condFilterQuery<T>

Returns: FilterQuery<T>

Defined in: packages/core/src/entity/Collection.ts:263


createLoadCountCondition#

PrivatecreateLoadCountCondition(cond: Dictionary<any>): Dictionary<any>

Parameters:#

NameType
condDictionary<any>

Returns: Dictionary<any>

Defined in: packages/core/src/entity/Collection.ts:296


createManyToManyCondition#

PrivatecreateManyToManyCondition(cond: Dictionary<any>): void

Parameters:#

NameType
condDictionary<any>

Returns: void

Defined in: packages/core/src/entity/Collection.ts:285


createOrderBy#

PrivatecreateOrderBy(orderBy?: QueryOrderMap): QueryOrderMap

Parameters:#

NameType
orderByQueryOrderMap

Returns: QueryOrderMap

Defined in: packages/core/src/entity/Collection.ts:273


getEntityManager#

PrivategetEntityManager(): any

Returns: any

Defined in: packages/core/src/entity/Collection.ts:253


getIdentifiers#

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

Type parameters:#

NameTypeDefault
UIPrimaryKeyValuePrimary<T> & IPrimaryKeyValue

Parameters:#

NameType
field?string

Returns: U[]

Inherited from: ArrayCollection

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


getItems#

getItems(check?: boolean): T[]

Returns the items (the collection must be initialized)

Parameters:#

NameTypeDefault value
checkbooleantrue

Returns: T[]

Overrides: ArrayCollection

Defined in: packages/core/src/entity/Collection.ts:102


getSnapshot#

getSnapshot(): undefined | T[]

internal

Returns: undefined | T[]

Defined in: packages/core/src/entity/Collection.ts:249


hydrate#

hydrate(items: T[]): void

internal

Parameters:#

NameType
itemsT[]

Returns: void

Overrides: ArrayCollection

Defined in: packages/core/src/entity/Collection.ts:143


incrementCount#

ProtectedincrementCount(value: number): void

Parameters:#

NameType
valuenumber

Returns: void

Inherited from: ArrayCollection

Defined in: packages/core/src/entity/ArrayCollection.ts:202


init#

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

Parameters:#

NameType
options?InitOptions<T>

Returns: Promise<Collection<T, O>>

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

init(populate?: string[], where?: FilterQuery<T>, orderBy?: QueryOrderMap): 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:192


isDirty#

isDirty(): boolean

Returns: boolean

Defined in: packages/core/src/entity/Collection.ts:183


isInitialized#

isInitialized(fully?: boolean): boolean

Parameters:#

NameTypeDefault value
fullybooleanfalse

Returns: boolean

Inherited from: ArrayCollection

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


loadCount#

loadCount(refresh?: boolean): 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

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: MatchingOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>): Promise<T[]>

Parameters:#

NameType
optionsMatchingOptions<T, readonly string[] | readonly keyof T[] | boolean | LoadStrategy | PopulateChildren<T>>

Returns: Promise<T[]>

Defined in: packages/core/src/entity/Collection.ts:77


modify#

Privatemodify(method: add | remove, items: T[]): void

Parameters:#

NameType
methodadd | remove
itemsT[]

Returns: void

Defined in: packages/core/src/entity/Collection.ts:307


populated#

populated(populated?: boolean): void

Parameters:#

NameTypeDefault value
populatedbooleantrue

Returns: void

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


propagate#

Protectedpropagate(item: T, method: add | remove): void

Parameters:#

NameType
itemT
methodadd | remove

Returns: void

Inherited from: ArrayCollection

Defined in: packages/core/src/entity/ArrayCollection.ts:162


propagateToInverseSide#

ProtectedpropagateToInverseSide(item: T, method: add | remove): void

Parameters:#

NameType
itemT
methodadd | remove

Returns: void

Inherited from: ArrayCollection

Defined in: packages/core/src/entity/ArrayCollection.ts:170


propagateToOwningSide#

ProtectedpropagateToOwningSide(item: T, method: add | remove): void

Parameters:#

NameType
itemT
methodadd | remove

Returns: void

Inherited from: ArrayCollection

Defined in: packages/core/src/entity/ArrayCollection.ts:178


remove#

remove(...items: (T | Reference<T>)[]): void

Parameters:#

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

Returns: void

Overrides: ArrayCollection

Defined in: packages/core/src/entity/Collection.ts:149


removeAll#

removeAll(): void

Returns: void

Inherited from: ArrayCollection

Defined in: packages/core/src/entity/ArrayCollection.ts:118


reorderItems#

PrivatereorderItems(items: T[], order: T[]): void

re-orders items after searching with $in operator

Parameters:#

NameType
itemsT[]
orderT[]

Returns: void

Defined in: packages/core/src/entity/Collection.ts:326


set#

set(items: (T | Reference<T>)[]): void

Parameters:#

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

Returns: void

Overrides: ArrayCollection

Defined in: packages/core/src/entity/Collection.ts:125


setDirty#

setDirty(dirty?: boolean): void

Parameters:#

NameTypeDefault value
dirtybooleantrue

Returns: void

Defined in: packages/core/src/entity/Collection.ts:187


shouldPopulate#

shouldPopulate(): boolean

Returns: boolean

Defined in: packages/core/src/entity/Collection.ts:174


shouldPropagateToCollection#

ProtectedshouldPropagateToCollection(collection: ArrayCollection<O, T>, method: add | remove): boolean

Parameters:#

NameType
collectionArrayCollection<O, T>
methodadd | remove

Returns: boolean

Inherited from: ArrayCollection

Defined in: packages/core/src/entity/ArrayCollection.ts:189


takeSnapshot#

takeSnapshot(): void

internal

Returns: void

Defined in: packages/core/src/entity/Collection.ts:241


toArray#

toArray(): Dictionary<any>[]

Returns: Dictionary<any>[]

Inherited from: ArrayCollection

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


toJSON#

toJSON(): Dictionary<any>[]

Returns: Dictionary<any>[]

Overrides: ArrayCollection

Defined in: packages/core/src/entity/Collection.ts:110


validateItemType#

PrivatevalidateItemType(item: T | Primary<T> | EntityData<T>): void

Parameters:#

NameType
itemT | Primary<T> | EntityData<T>

Returns: void

Defined in: packages/core/src/entity/Collection.ts:344


validateModification#

PrivatevalidateModification(items: T[]): void

Parameters:#

NameType
itemsT[]

Returns: void

Defined in: packages/core/src/entity/Collection.ts:350


create#

Staticcreate<T, O>(owner: O, prop: keyof O, items: undefined | T[], initialized: boolean): 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:#

NameDefault
T-
Oany

Parameters:#

NameType
ownerO
propkeyof O
itemsundefined | T[]
initializedboolean

Returns: Collection<T, O>

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

Last updated on by Renovate Bot