> For the complete documentation index, see [llms.txt](https://yeti-dev.gitbook.io/apollo-server-adonis-directive-pack/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yeti-dev.gitbook.io/apollo-server-adonis-directive-pack/api/relationship/belongsto.md).

# @belongsTo

Belongs to (one or more)

### For a separate add use

```javascript
/* ... */
const {
  BelongsToDirective,
  BelongsToTypeDefs
} = require('apollo-server-adonis-directives-pack/src/directives/relationship/BelongsTo')

makeExecutableSchema({ 
  /* ... */ 
  typeDefs: [ BelongsToTypeDefs, /* ... */ ],
  schemaDirectives: { BelongsToDirective, /* ... */} 
})
```

### Definition

{% code title="BelongsToTypeDefs" %}

```graphql
directive @belongsTo(
  # By default, the model will be calculated from the name
  # of the returned "type" with the prefix 'App/Model/'
  model: String,
  # By default ownerColumn = 'id'
  ownerColumn: String,
  # By default, the column will be calculated from the name 
  # of the returned "type" with the postfix '_id'
  localColumn:String) on FIELD_DEFINITION
```

{% endcode %}

### Example

```graphql
type User {
    id: ID!
    name: String
    country_id: Int!
}

type Post {
    id: ID!
    title: String!
    text: String
    user_id: Int!
    user: User @belongsTo #localColumn: user_id
}

type Country {
    id: ID!
    name: String
    users: [User] @belondsTo(localColumn: "id", ownerColumn: "country_id")
}
```
