Skip to main content
Version: 4.4

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>

Inherited from: ArrayCollection

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

Properties#

_count#

Protected Optional _count: undefined | 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:13


_populated#

Private _populated: boolean= false

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


dirty#

Private dirty: boolean= false

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


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@41631?: unknown ; __@PrimaryKeyType@41543?: unknown ; __helper?: undefined | IWrappedEntityInternal<O, keyof O, keyof O> ; __meta?: undefined | EntityMetadata<O> ; __platform?: undefined | Platform }

Inherited from: ArrayCollection.owner


snapshot#

Private snapshot: undefined | T[]

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

Accessors#

length#

length(): number

Returns: number

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


property#

property(): EntityProperty<T>

internal

Returns: EntityProperty<T>

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

Methods#

[Symbol.iterator]#

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

Returns: IterableIterator<T>

Inherited from: ArrayCollection

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


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:91


cancelOrphanRemoval#

PrivatecancelOrphanRemoval(items: T[]): void

Parameters:#

NameType
itemsT[]

Returns: void

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


checkInitialized#

PrivatecheckInitialized(): void

Returns: void

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


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:134


count#

count(): number

Returns: number

Overrides: ArrayCollection

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


createCondition#

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

Type parameters:#

NameType
TAnyEntity<T>

Parameters:#

NameTypeDefault value
condFilterQuery<T>...

Returns: FilterQuery<T>

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


createLoadCountCondition#

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

Parameters:#

NameType
condDictionary<any>

Returns: Dictionary<any>

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


createManyToManyCondition#

PrivatecreateManyToManyCondition(cond: Dictionary<any>): void

Parameters:#

NameType
condDictionary<any>

Returns: void

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


createOrderBy#

PrivatecreateOrderBy(orderBy?: QueryOrderMap): QueryOrderMap

Parameters:#

NameTypeDefault value
orderByQueryOrderMap...

Returns: QueryOrderMap

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


getIdentifiers#

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

Type parameters:#

NameTypeDefault
UIPrimaryKeyValuePrimary<T\> & string \

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:75


getSnapshot#

getSnapshot(): undefined | T[]

internal

Returns: undefined | T[]

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


hydrate#

hydrate(items: T[]): void

internal

Parameters:#

NameType
itemsT[]

Returns: void

Overrides: ArrayCollection

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


incrementCount#

ProtectedincrementCount(value: number): void

Parameters:#

NameType
valuenumber

Returns: void

Inherited from: ArrayCollection

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


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:164

init(populate?: string[], where?: { __@PrimaryKeyType@41543?: any } | NonNullable<Query<T>>, orderBy?: QueryOrderMap): Promise<Collection<T, O>>

Parameters:#

NameType
populate?string[]
where?{ __@PrimaryKeyType@41543?: any } | NonNullable<Query<T>>
orderBy?QueryOrderMap

Returns: Promise<Collection<T, O>>

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


isDirty#

isDirty(): boolean

Returns: boolean

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


isInitialized#

isInitialized(fully?: boolean): boolean

Parameters:#

NameTypeDefault value
fullybooleanfalse

Returns: boolean

Inherited from: ArrayCollection

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


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:54


loadItems#

loadItems(): Promise<T[]>

Initializes the collection and returns the items

Returns: Promise<T[]>

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


modify#

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

Parameters:#

NameType
methodadd | remove
itemsT[]

Returns: void

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


populated#

populated(populated?: boolean): void

Parameters:#

NameTypeDefault value
populatedbooleantrue

Returns: void

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


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:157


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:165


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:173


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:122


removeAll#

removeAll(): void

Returns: void

Inherited from: ArrayCollection

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


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:292


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:98


setDirty#

setDirty(dirty?: boolean): void

Parameters:#

NameTypeDefault value
dirtybooleantrue

Returns: void

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


shouldPopulate#

shouldPopulate(): boolean

Returns: boolean

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


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:184


takeSnapshot#

takeSnapshot(): void

internal

Returns: void

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


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:83


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:310


validateModification#

PrivatevalidateModification(items: T[]): void

Parameters:#

NameType
itemsT[]

Returns: void

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


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:28

Last updated on by Martin Adámek