Skip to main content
Version: 5.9

ArrayCollection <T, O>

Hierarchy

  • ArrayCollection
    • Collection

Indexable

[k: number]: T

Index

Constructors

constructor

  • new ArrayCollection<T, O>(owner: O, items?: T[]): ArrayCollection<T, O>
  • Type parameters

    • T: object
    • O: object

    Parameters

    • owner: O
    • optionalitems: T[]

    Returns ArrayCollection<T, O>

Properties

readonlyowner

owner: O

Accessors

length

  • get length(): number
  • Returns number

Methods

[custom]

  • [custom](depth: number): string
  • Parameters

    • depth: number

    Returns string

[iterator]

  • [iterator](): IterableIterator<T>
  • Returns IterableIterator<T>

add

  • add(entity: T | Reference<T> | (T | Reference<T>)[], ...entities: (T | Reference<T>)[]): void
  • Parameters

    • entity: T | Reference<T> | (T | Reference<T>)[]
    • rest...entities: (T | Reference<T>)[]

    Returns void

contains

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

    • item: T | Reference<T>
    • optionalcheck: boolean

    Returns boolean

count

  • count(): number
  • Returns number

exists

  • exists(cb: (item: T) => boolean): boolean
  • Tests for the existence of an element that satisfies the given predicate.


    Parameters

    • cb: (item: T) => boolean

      Returns boolean

    filter

    • filter(cb: (item: T, index: number) => boolean): T[]
    • Extracts a subset of the collection items.


      Parameters

      • cb: (item: T, index: number) => boolean

        Returns T[]

      find

      • find(cb: (item: T, index: number) => boolean): undefined | T
      • Returns the first element of this collection that satisfies the predicate.


        Parameters

        • cb: (item: T, index: number) => boolean

          Returns undefined | T

        getIdentifiers

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

          • U: IPrimaryKeyValue = Object

          Parameters

          • optionalfield: string

          Returns U[]

        getItems

        • getItems(): T[]
        • Returns T[]

        indexBy

        • indexBy<K1, K2>(key: K1): Record<Object, T>
        • indexBy<K1, K2>(key: K1, valueKey: K2): Record<Object, T[K2]>
        • 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<Object, T>

        isDirty

        • isDirty(): boolean
        • Returns boolean

        isEmpty

        • isEmpty(): boolean
        • Returns boolean

        isInitialized

        • isInitialized(fully?: boolean): boolean
        • Parameters

          • fully: boolean = false

          Returns boolean

        loadCount

        • loadCount(): Promise<number>
        • Returns Promise<number>

        map

        • map<R>(mapper: (item: T, index: number) => R): R[]
        • Maps the collection items based on your provided mapper function.


          Type parameters

          • R

          Parameters

          • mapper: (item: T, index: number) => R

            Returns R[]

          reduce

          • reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R
          • Maps the collection items based on your provided mapper function to a single object.


            Type parameters

            • R

            Parameters

            • cb: (obj: R, item: T, index: number) => R
              • initial: R = ...

              Returns R

            remove

            • remove(entity: T | Reference<T> | (T | Reference<T>)[], ...entities: (T | Reference<T>)[]): void
            • 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.


              Parameters

              • entity: T | Reference<T> | (T | Reference<T>)[]
              • rest...entities: (T | Reference<T>)[]

              Returns void

            removeAll

            • removeAll(): void
            • 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

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

              • items: (T | Reference<T>)[]

              Returns void

            setDirty

            • setDirty(dirty?: boolean): void
            • Parameters

              • dirty: boolean = true

              Returns void

            slice

            • slice(start?: number, end?: number): T[]
            • 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

              • start: number = 0
              • optionalend: number

              Returns T[]

            toArray

            • toArray(): EntityDTO<T>[]
            • Returns EntityDTO<T>[]

            toJSON

            • toJSON(): EntityDTO<T>[]
            • Returns EntityDTO<T>[]