Collection <T, O>
Hierarchy
- ArrayCollection<T, O>- Collection
 
Index
Constructors
constructor
- Type parameters- T: object
- O: object = object
 - Parameters- owner: O
- optionalitems: T[]
- initialized: boolean = true
 - Returns Collection<T, O>
Properties
readonlyowner
Accessors
length
- Returns number
Methods
[iterator]
- Returns IterableIterator<T>
add
contains
- Type parameters- TT: object
 - Parameters- item: TT | Reference<TT>
- check: boolean = true
 - Returns boolean
count
- Returns number
exists
- Parameters- cb: (item) => boolean
 - Returns boolean
filter
- Extracts a subset of the collection items. - Parameters- cb: (item, index) => boolean
 - Returns T[]
find
- Returns the first element of this collection that satisfies the predicate. - Parameters- cb: (item, index) => boolean
 - Returns undefined | T
getIdentifiers
- Type parameters- U: IPrimaryKeyValue = (T extends { [PrimaryKeyProp]?: PK } ? PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : PK extends keyof T[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T) & IPrimaryKeyValue
 - Parameters- optionalfield: string
 - Returns U[]
getItems
- Returns the items (the collection must be initialized) - Parameters- check: boolean = true
 - Returns T[]
indexBy
- Maps the collection items to a dictionary, indexed by the key you specify. If there are more items with the same key, only the first one will be present. - Type parameters- K1: string | number | symbol
- K2: string | number | symbol = never
 - Parameters- key: K1
 - Returns Record<T[K1] & PropertyKey, T>
init
- Type parameters- TT: object
- P: string = never
 - Parameters- options: InitCollectionOptions<TT, P, *, never> = {}
 - Returns Promise<LoadedCollection<Loaded<TT, P>>>
isDirty
- Returns boolean
isEmpty
- Returns boolean
isInitialized
- Parameters- fully: boolean = false
 - Returns boolean
load
- Ensures the collection is loaded first (without reloading it if it already is loaded). Returns the Collection instance (itself), works the same as - Reference.load().- Type parameters- TT: object
- P: string = never
 - Parameters- options: InitCollectionOptions<TT, P, *, never> = {}
 - Returns Promise<LoadedCollection<Loaded<TT, P>>>
loadCount
- Gets the count of collection items from database instead of counting loaded items. The value is cached (unless you use the - whereoption), use- refresh: trueto force reload it.- Parameters- options: boolean | LoadCountOptions<T> = {}
 - Returns Promise<number>
loadItems
- Initializes the collection and returns the items - Type parameters- TT: object
- P: string = never
 - Parameters- optionaloptions: InitCollectionOptions<TT, P, *, never>
 - Returns Promise<Loaded<TT, P>[]>
map
- Maps the collection items based on your provided mapper function. - Type parameters- R
 - Parameters- mapper: (item, index) => R
 - Returns R[]
matching
- Type parameters- TT: object
- P: string = never
 - Parameters- options: MatchingOptions<T, P>
 - Returns Promise<Loaded<TT, P>[]>
populated
- Parameters- populated: undefined | boolean = true
 - Returns void
reduce
- Maps the collection items based on your provided mapper function to a single object. - Type parameters- R
 - Parameters- cb: (obj, item, index) => R
- initial: R = ...
 - Returns R
remove
- Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity, it means we are disconnecting the relation - removing items from collection, not removing entities from database - - Collection.remove()is not the same as- em.remove(). If we want to delete the entity by removing it from collection, we need to enable- orphanRemoval: true, which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.- Type parameters- TT: object
 - Parameters- entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | (item) => boolean
- rest...entities: (TT | Reference<TT>)[]
 - Returns void
removeAll
- Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity, it means we are disconnecting the relation - removing items from collection, not removing entities from database - - Collection.remove()is not the same as- em.remove(). If we want to delete the entity by removing it from collection, we need to enable- orphanRemoval: true, which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.- Returns void
set
- Parameters- items: Iterable<T | Reference<T>>
 - Returns void
setDirty
- Parameters- dirty: boolean = true
 - Returns void
shouldPopulate
- Parameters- optionalpopulated: boolean
 - Returns boolean
slice
- Extracts a slice of the collection items starting at position start to end (exclusive) of the collection. If end is null it returns all elements from start to the end of the collection. - Parameters- optionalstart: number
- optionalend: number
 - Returns T[]
toArray
- Type parameters- TT: object
 - Returns EntityDTO<TT>[]
toJSON
- Type parameters- TT: object
 - Returns EntityDTO<TT>[]
staticcreate
- Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides) - Type parameters- T: object
- O: object = object
 - Parameters- owner: O
- prop: EntityKey<O>
- items: undefined | T[]
- initialized: boolean
 - Returns Collection<T, O>
Tests for the existence of an element that satisfies the given predicate.