[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Relation](https://evolu.dev/docs/api-reference/common/Relation) › RefCountedRelation

Defined in: [packages/common/src/Relation.ts:323](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L323)

Bidirectional relation with a positive retain count for every active pair.

Logical equality and canonical representatives follow the same lookup rules
as [Relation](https://evolu.dev/docs/api-reference/common/Relation/interfaces/Relation). The first active representative on each side remains
canonical until that value has no active pairs. Increment and decrement
return those representatives so callers can reliably handle pair transitions
without repeating lookup or canonicalization logic.

Unlike [Relation](https://evolu.dev/docs/api-reference/common/Relation/interfaces/Relation)'s live iterators, directional and entry reads return
snapshots so callers can mutate this relation while iterating. Their order
follows first insertion of the current canonical representatives and pairs.

## Properties

<a id="clear"></a>

### clear

```ts
readonly clear: () => void;
```

Defined in: [packages/common/src/Relation.ts:369](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L369)

Removes all pair counts and both directional indexes.

### decrement

```ts
readonly decrement: (a: A, b: B) => {
  a: A;
  b: B;
  count: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;
};
```

Defined in: [packages/common/src/Relation.ts:339](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L339)

Decrements a pair count and returns its canonical values and new count.
Decrementing a missing pair is a programmer error checked with
[assert](https://evolu.dev/docs/api-reference/common/Assert/variables/assert).

### getAs

```ts
readonly getAs: (b: B) => readonly A[];
```

Defined in: [packages/common/src/Relation.ts:352](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L352)

Returns a snapshot of canonical A values related to `b`.

### getBs

```ts
readonly getBs: (a: A) => readonly B[];
```

Defined in: [packages/common/src/Relation.ts:355](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L355)

Returns a snapshot of canonical B values related to `a`.

### getCount

```ts
readonly getCount: (a: A, b: B) => number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;
```

Defined in: [packages/common/src/Relation.ts:349](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L349)

Returns the pair count, or zero when the pair is absent.

### getEntries

```ts
readonly getEntries: () => readonly readonly [A, B, number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">][];
```

Defined in: [packages/common/src/Relation.ts:364](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L364)

Returns a snapshot of every canonical pair and its positive count.

### hasA

```ts
readonly hasA: (a: A) => boolean;
```

Defined in: [packages/common/src/Relation.ts:358](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L358)

Returns whether an A value has at least one active pair.

### hasB

```ts
readonly hasB: (b: B) => boolean;
```

Defined in: [packages/common/src/Relation.ts:361](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L361)

Returns whether a B value has at least one active pair.

### increment

```ts
readonly increment: (a: A, b: B) => {
  a: A;
  b: B;
  count: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">;
};
```

Defined in: [packages/common/src/Relation.ts:325](https://github.com/evoluhq/evolu/blob/037c390af081e9944d616ff298a729515c5c5ab7/packages/common/src/Relation.ts#L325)

Increments a pair count and returns its canonical values and new count.