API Reference
interfaces
Includeprojection

@coasys/ad4m / Exports / IncludeProjection

Interface: IncludeProjection

A lightweight projection that computes a scalar or list value from a relation without fully hydrating the linked instances.

Keys in IncludeMap that begin with $ are treated as projections. Results are attached directly to each queried instance under the same key.

Example

// Attach a like-count to each post
const posts = await Post.findAll(perspective, {
  include: {
    $likeCount: { from: 'likes', count: true },
    $myLike:    { from: 'likes', limit: 1 },
  }
});
posts[0].$likeCount  // number
posts[0].$myLike     // string ID or null

Table of contents

Properties

Properties

count

• Optional count: true

When true, attaches an integer count instead of a list.

Defined in

core/src/model/types.ts:291 (opens in a new tab)


from

• from: string

The relation name on the parent model to project over.

Defined in

core/src/model/types.ts:289 (opens in a new tab)


limit

• Optional limit: number

Limit results (when 1, the attached value is unwrapped to a scalar).

Defined in

core/src/model/types.ts:316 (opens in a new tab)


order

• Optional order: Order

Order results before applying limit.

Defined in

core/src/model/types.ts:318 (opens in a new tab)


transitive

• Optional transitive: boolean

Project over everything reachable through from, not just one step.

{ from: 'comments', count: true, transitive: true } is the whole conversation under each row rather than its direct replies — which is what a reader takes "42 replies" on a collapsed branch to mean. The projection query is already grouped per parent and already asked of every row at once, so this adds no round trip.

Cannot be combined with a filter on the link's author or timestamp: those read the reification of one link, and a path has none. Such a projection is skipped with a warning rather than silently answering a different question.

Defined in

core/src/model/types.ts:305 (opens in a new tab)


where

• Optional where: Where

Post-hydration where clause applied to the target instances.

Defined in

core/src/model/types.ts:314 (opens in a new tab)