> 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/hasmany.md).

# @hasMany

One to many relationship

### For a separate add use

```javascript
/* ... */
const {
  HasManyDirective,
  HasManyTypeDefs
} = require('apollo-server-adonis-directives-pack/src/directives/relationship/HasMany')

makeExecutableSchema({ 
  /* ... */ 
  typeDefs: [ HasManyTypeDefs, /* ... */ ],
  schemaDirectives: { HasManyDirective, /* ... */} 
})
```

### Definition

{% code title="HasManyTypeDefs" %}

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

{% endcode %}

### Example

```graphql
type User {
    id: ID!
    name: String
    posts: [Post] @hasMany #ownerColumn: user_id
}

type Post {
    id: ID!
    title: String!
    text: String
    user_id: Int!
}
```

{% hint style="warning" %}
This directive uses a DataLoader but does not cache the results.
{% endhint %}
