Collection <T, O>
Hierarchy
- ArrayCollection<T, O>
- Collection
Index
Constructors
constructor
Type parameters
- T
- O = unknown
Parameters
owner: O
optionalitems: T[]
initialized: boolean = true
Returns Collection<T, O>
Properties
readonlyowner
Accessors
length
Returns number
Methods
[custom]
Parameters
depth: number
Returns string
[iterator]
Returns IterableIterator<T>
add
Parameters
rest...items: (T | Reference<T>)[]
Returns void
contains
Parameters
item: T | Reference<T>
check: boolean = true
Returns boolean
count
Returns number
getIdentifiers
getItems
Parameters
check: boolean = true
Returns T[]
init
Type parameters
- P: string = never
Parameters
options: InitOptions<T, P> = {}
Returns Promise<LoadedCollection<Loaded<T, P>>>
isDirty
Returns boolean
isInitialized
Parameters
fully: boolean = false
Returns boolean
loadCount
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
refresh: boolean = false
Returns Promise<number>
loadItems
Initializes the collection and returns the items
Type parameters
- P: string = never
Parameters
optionaloptions: InitOptions<T, P>
Returns Promise<Loaded<T, P>[]>
matching
Type parameters
- P: string = never
Parameters
options: MatchingOptions<T, P>
Returns Promise<Loaded<T, P>[]>
populated
Parameters
populated: boolean = true
Returns void
remove
Remove specified item(s) from the collection. Note that removing item from collection does 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 asem.remove()
. If we want to delete the entity by removing it from collection, we need to enableorphanRemoval: true
, which tells the ORM we don’t want orphaned entities to exist, so we know those should be removed.Parameters
rest...items: (T | Reference<T> | (item: T) => boolean)[]
Returns void
removeAll
Remove all items from the collection. Note that removing items from collection does 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 asem.remove()
. If we want to delete the entity by removing it from collection, we need to enableorphanRemoval: 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: (T | Reference<T>)[]
Returns void
setDirty
Parameters
dirty: boolean = true
Returns void
shouldPopulate
Returns boolean
toArray
Returns EntityDTO<T>[]
toJSON
Returns EntityDTO<T>[]
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
- O = any
Parameters
owner: O
prop: keyof O
items: undefined | T[]
initialized: boolean
Returns Collection<T, O>
Returns the items (the collection must be initialized)