---
lang: en
title: 'API docs: repository.createbelongstoaccessor'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/repository
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 | [BelongsToDefinition](./repository.belongstodefinition.md) |  |
|  targetRepoGetter | [Getter](./context.getter.md)<!-- -->&lt;[EntityCrudRepository](./repository.entitycrudrepository.md)<!-- -->&lt;Target, TargetId&gt;&gt; |  |
|  sourceRepository | [EntityCrudRepository](./repository.entitycrudrepository.md)<!-- -->&lt;Source, SourceId&gt; |  |

<b>Returns:</b>

[BelongsToAccessor](./repository.belongstoaccessor.md)<!-- -->&lt;Target, SourceId&gt;


