Documentation
    Preparing search index...

    Class CollectionProperty

    A specialized backend property that represents a one-to-many or many-to-many relationship. Unlike the core CollectionProperty, this property acts as a dynamic query builder, fetching related PersistedBaseObject instances directly from the database when accessed.

    const users = new CollectionProperty({
    name: 'employees',
    instanceOf: User,
    parentKey: 'companyUri' // The field in 'User' that stores the company ID
    });

    // Fetch the collection from the database
    const results = await users.val();
    console.log(results); // Array of User objects

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _allows: string[] = []
    _backend: any
    _defaultValue: any
    _events: { [key: string]: Function } = {}
    _filters: Filter | Filter[] | undefined = undefined
    _hasChanged: boolean
    _htmlType: PropertyHTMLType = 'off'
    _id: string
    _instanceOf: typeof PersistedBaseObject
    _mandatory: boolean = false
    _name: string
    _parent: DataObjectClass<any> | undefined
    _parentKey: string
    _protected: boolean = false
    _query: Query<any>
    _value: any[] | DataObjectClass<any>[] | ObjectUri[] | undefined = undefined
    EVENT_ONCHANGE: string = 'onChange'

    Event name triggered when the property value changes.

    EVENT_ONDELETE: string = 'onDelete'

    Event name triggered when the property is deleted.

    TYPE: string = 'collection'

    Type identifier for the property registry.

    Accessors

    • get allows(): string[]

      Returns string[]

    • get hasChanged(): boolean

      Returns boolean

    • set hasChanged(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get htmlType(): PropertyHTMLType

      Returns PropertyHTMLType

    • set htmlType(type: PropertyHTMLType): void

      Parameters

      Returns void

    • get mandatory(): boolean

      Returns boolean

    • get name(): string

      Returns string

    • get protected(): boolean

      Returns boolean

    Methods

    • Parameters

      • value: boolean | undefined

      Returns value is true | undefined

    • Parameters

      Returns any

    • Applies an anonymous function to each item in the collection. Fetches fully instantiated model class instances from the database if not hydrated.

      Parameters

      • fn: (item: any) => any

        The anonymous callback function to apply to each item.

      Returns Promise<any[]>

      A promise resolving to the results of the callback applications.

    • Calculates the average of the numeric values of a property across items in the collection. Delegates to database query if not hydrated.

      Parameters

      • property: string

        The name of the property to average.

      Returns Promise<number>

      A promise resolving to the average of all numeric values.

    • Creates a deep clone of the current property instance, preserving its prototype chain.

      Returns any

      A new independent instance of the property.

    • Returns the count of items in the collection, optionally filtered by a predicate callback. If no predicate is provided and the collection is not hydrated, it runs a fast database query.

      Parameters

      • Optionalpredicate: (item: any) => boolean

        An optional filter callback to run on each item.

      Returns Promise<number>

      A promise resolving to the count of matching items.

    • Retrieves all distinct values of a property across the collection items. Delegates to database query if not hydrated.

      Parameters

      • property: string

        The name of the property.

      Returns Promise<any[]>

      A promise resolving to an array of unique property values.

    • Constructs or retrieves the backend query builder for this collection. This allows chaining further database conditions before execution.

      Parameters

      • filters: Filter[] | undefined = undefined

        Optional array of filters to apply to the collection query.

      Returns Query<any>

      A Query object ready to be executed against the backend.

    • Groups the collection items by the values of a specific property. Fetches and hydrates the collection first if not already hydrated.

      Parameters

      • property: string

        The name of the property to group by.

      Returns Promise<Record<string, any[]>>

      A promise resolving to a dictionary object.

    • Returns the maximum value of a numeric property across the collection items. Delegates to database query if not hydrated.

      Parameters

      • property: string

        The name of the property.

      Returns Promise<number | undefined>

      A promise resolving to the maximum numeric value found, or undefined.

    • Returns the minimum value of a numeric property across the collection items. Delegates to database query if not hydrated.

      Parameters

      • property: string

        The name of the property.

      Returns Promise<number | undefined>

      A promise resolving to the minimum numeric value found, or undefined.

    • Plucks a specific property from each item in the collection. Fetches and hydrates the collection first if not already hydrated.

      Parameters

      • property: string

        The name of the property to extract.

      Returns Promise<any[]>

      A promise resolving to an array containing the extracted property values.

    • Overrides the default set method. Normally, a backend collection's value is retrieved dynamically via queries, but it can be manually hydrated.

      Parameters

      • value: any[]

        The array of objects or URIs to set.

      • setChanged: boolean = true

        Whether to mark the property as modified.

      Returns CollectionProperty

      The property instance for chaining.

    • Sums the numeric values of a property across items in the collection. Delegates to database query if not hydrated.

      Parameters

      • property: string

        The name of the property to sum.

      Returns Promise<number>

      A promise resolving to the sum of all numeric values.

    • Serializes the current explicitly set value of the collection. Note: This does not trigger a database fetch.

      Returns any[] | DataObjectClass<any>[] | ObjectUri[] | undefined

      The raw internal value array.

    • Executes the backend query and resolves the collection of related objects.

      Parameters

      • transform: returnAs = returnAs.AS_DATAOBJECTS

        The format in which the results should be returned (e.g. AS_DATAOBJECTS).

      Returns Promise<QueryResultType<any>>

      A promise resolving to the query result containing the objects.