# key()

Generates one or several entity key(s) for the Model. This method accepts the following arguments:

```javascript
MyModel.key(
    /* {int|string}. -- Can also be an Array of ids to generate */
    <id>,
    /* {Array} -- optional. ex: ['ParentEntity', 1234 ] */
    <ancestors>,
    /* {string} -- optional. A specific namespace */
    <namespace>
)
```

Example:

```javascript
const User = require('./user.model');

// basic
const entityKey = User.key(123);

// with ancestors and namespace
const entityKey = User.key(123, ['Parent', 'keyname'], 'dev.domain.com');

// with an Array of ids
const entityKeys = User.key([123, 456]);
console.log(entityKeys.length); // 2
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sebloix.gitbook.io/gstore-node/model/methods/key.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
