Member Junction
    Preparing search index...

    Function TransformSimpleObjectToEntityObject

    • Converts an array of plain JavaScript objects into fully-hydrated BaseEntity subclass instances, using Promise.all for parallel creation.

      This is the canonical way to batch-convert raw data (e.g. from a custom stored procedure, RunQuery result, or any non-RunView data source) into typed entity objects that support .Save(), .Load(), dirty-tracking, and all other BaseEntity capabilities.

      Items that are already BaseEntity instances (detected via instanceof or duck-typing the .Save() method) are returned as-is, making this function safe to call on mixed arrays.

      Performance note: All entity creations run in parallel via Promise.all. For large arrays (500+ items), consider chunking to avoid memory pressure.

      Type Parameters

      Parameters

      • md: IMetadataProvider

        The metadata provider used to create entity instances. On the client side this is typically new Metadata(); on the server side it is the active IMetadataProvider (e.g. Metadata.Provider).

      • entityName: string

        The MemberJunction entity name, e.g. 'MJ: Conversation Details'. Must match a registered entity exactly (case-insensitive, trimmed).

      • items: Record<string, unknown>[]

        Plain objects whose keys map to entity field names. Each object is passed to entity.LoadFromData() which populates the entity without marking fields as dirty (i.e. the entity starts in a "clean" / not-new state).

      • OptionalcontextUser: UserInfo

        Optional user context for server-side operations. Required on the server where multiple users are served concurrently; can be omitted on the client where user context is already established.

      Returns Promise<T[]>

      A parallel-resolved array of typed entity objects in the same order as the input items array.

      import { Metadata, TransformSimpleObjectToEntityObject } from '@memberjunction/core';

      const md = new Metadata();
      const rawRows = queryResult.Results as SomeRawType[];
      const entities = await TransformSimpleObjectToEntityObject<MyEntity>(
      md, 'My Entity Name', rawRows, contextUser
      );
      // entities is MyEntity[] — fully usable with .Save(), .Load(), etc.