Version: 4.3

Class: Collection<T, O>

Type parameters

NameDefault
T-
Ounknown

Hierarchy

Indexable

▪ [k: number]: T

Constructors

constructor

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

Overrides ArrayCollection.constructor

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

Parameters:

NameTypeDefault value
ownerO-
items?T[]-
initializedbooleantrue

Returns: Collection

Properties

_count

Protected Optional _count: number

Inherited from ArrayCollection._count

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


_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:11


items

Protected Readonly items: Set<T> = new Set<T>()

Inherited from ArrayCollection.items

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


owner

Readonly owner: O & AnyEntity<O>

Inherited from ArrayCollection.owner

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


snapshot

Private snapshot: T[] | undefined = []

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

Accessors

length

• get length(): number

Inherited from ArrayCollection.length

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

Returns: number


property

• get property(): EntityProperty<T>

Inherited from ArrayCollection.property

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

internal

Returns: EntityProperty<T>

Methods

[Symbol.iterator]

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

Inherited from ArrayCollection.[Symbol.iterator]

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

Returns: IterableIterator<T>


add

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

Overrides ArrayCollection.add

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

Parameters:

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

Returns: void


cancelOrphanRemoval

PrivatecancelOrphanRemoval(items: T[]): void

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

Parameters:

NameType
itemsT[]

Returns: void


checkInitialized

PrivatecheckInitialized(): void

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

Returns: void


contains

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

Overrides ArrayCollection.contains

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

Parameters:

NameTypeDefault value
itemT | Reference<T>-
checkbooleantrue

Returns: boolean


count

count(): number

Overrides ArrayCollection.count

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

Returns: number


createCondition

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

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

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
condFilterQuery<T>{}

Returns: FilterQuery<T>


createLoadCountCondition

PrivatecreateLoadCountCondition(cond: Dictionary): Dictionary<any>

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

Parameters:

NameType
condDictionary

Returns: Dictionary<any>


createManyToManyCondition

PrivatecreateManyToManyCondition(cond: Dictionary): void

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

Parameters:

NameType
condDictionary

Returns: void


createOrderBy

PrivatecreateOrderBy(orderBy?: QueryOrderMap): QueryOrderMap

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

Parameters:

NameTypeDefault value
orderByQueryOrderMap{}

Returns: QueryOrderMap


getIdentifiers

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

Inherited from ArrayCollection.getIdentifiers

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

Type parameters:

NameTypeDefault
UIPrimaryKeyPrimary\<T> & IPrimaryKey

Parameters:

NameType
field?string

Returns: U[]


getItems

getItems(check?: boolean): T[]

Overrides ArrayCollection.getItems

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

Returns the items (the collection must be initialized)

Parameters:

NameTypeDefault value
checkbooleantrue

Returns: T[]


getSnapshot

getSnapshot(): T[]

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

internal

Returns: T[]


hydrate

hydrate(items: T[]): void

Overrides ArrayCollection.hydrate

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

internal

Parameters:

NameType
itemsT[]

Returns: void


incrementCount

ProtectedincrementCount(value: number): void

Inherited from ArrayCollection.incrementCount

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

Parameters:

NameType
valuenumber

Returns: void


init

init(options?: InitOptions<T>): Promise<this>

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

Parameters:

NameType
options?InitOptions<T>

Returns: Promise<this>

init(populate?: string[], where?: FilterQuery<T>, orderBy?: QueryOrderMap): Promise<this>

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

Parameters:

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

Returns: Promise<this>


isDirty

isDirty(): boolean

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

Returns: boolean


isInitialized

isInitialized(fully?: boolean): boolean

Inherited from ArrayCollection.isInitialized

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

Parameters:

NameTypeDefault value
fullybooleanfalse

Returns: boolean


loadCount

loadCount(refresh?: boolean): Promise<number>

Overrides ArrayCollection.loadCount

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

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>


loadItems

loadItems(): Promise<T[]>

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

Initializes the collection and returns the items

Returns: Promise<T[]>


modify

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

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

Parameters:

NameType
method"add" | "remove"
itemsT[]

Returns: void


populated

populated(populated?: boolean): void

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

Parameters:

NameTypeDefault value
populatedbooleantrue

Returns: void


propagate

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

Inherited from ArrayCollection.propagate

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

Parameters:

NameType
itemT
method"add" | "remove"

Returns: void


propagateToInverseSide

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

Inherited from ArrayCollection.propagateToInverseSide

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

Parameters:

NameType
itemT
method"add" | "remove"

Returns: void


propagateToOwningSide

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

Inherited from ArrayCollection.propagateToOwningSide

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

Parameters:

NameType
itemT
method"add" | "remove"

Returns: void


remove

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

Overrides ArrayCollection.remove

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

Parameters:

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

Returns: void


removeAll

removeAll(): void

Inherited from ArrayCollection.removeAll

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

Returns: void


reorderItems

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

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

re-orders items after searching with $in operator

Parameters:

NameType
itemsT[]
orderT[]

Returns: void


set

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

Overrides ArrayCollection.set

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

Parameters:

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

Returns: void


setDirty

setDirty(dirty?: boolean): void

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

Parameters:

NameTypeDefault value
dirtybooleantrue

Returns: void


shouldPopulate

shouldPopulate(): boolean

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

Returns: boolean


shouldPropagateToCollection

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

Inherited from ArrayCollection.shouldPropagateToCollection

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

Parameters:

NameType
collectionArrayCollection<O, T>
method"add" | "remove"

Returns: boolean


takeSnapshot

takeSnapshot(): void

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

internal

Returns: void


toArray

toArray(): Dictionary[]

Inherited from ArrayCollection.toArray

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

Returns: Dictionary[]


toJSON

toJSON(): Dictionary[]

Overrides ArrayCollection.toJSON

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

Returns: Dictionary[]


validateItemType

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

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

Parameters:

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

Returns: void


validateModification

PrivatevalidateModification(items: T[]): void

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

Parameters:

NameType
itemsT[]

Returns: void


create

Staticcreate<T, O>(owner: O, prop: keyof O, items: undefined | T[], initialized: boolean): Collection<T, O>

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

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>

Last updated on by Martin Adámek