---
lang: en
title: 'API docs: repository.createbelongstoaccessor'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
permalink: /doc/en/lb4/apidocs.repository.createbelongstoaccessor.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/repository](./repository.md) &gt; [createBelongsToAccessor](./repository.createbelongstoaccessor.md)

## createBelongsToAccessor() function

Enforces a BelongsTo constraint on a repository

<b>Signature:</b>

```typescript
export declare function createBelongsToAccessor<Target extends Entity, TargetId, Source extends Entity, SourceId>(belongsToMetadata: BelongsToDefinition, targetRepoGetter: Getter<EntityCrudRepository<Target, TargetId>>, sourceRepository: EntityCrudRepository<Source, SourceId>): BelongsToAccessor<Target, SourceId>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  belongsToMetadata | <code>BelongsToDefinition</code> |  |
|  targetRepoGetter | <code>Getter&lt;EntityCrudRepository&lt;Target, TargetId&gt;&gt;</code> |  |
|  sourceRepository | <code>EntityCrudRepository&lt;Source, SourceId&gt;</code> |  |

<b>Returns:</b>

`BelongsToAccessor<Target, SourceId>`


