# model()

With this method you can access a Model from an entity instance.

```javascript
const BlogPost = require('blog-post.model');
const blogEntity = new BlogPost({ title: 'Blog title' });

blogEntity.save().then(() => {
    const Image = blogEntity.model('Image'); // access the 'Image' Model
    const imageEntity = new Image({ uri: 'http://domain.com/image.jpg' });
    ...
});

// Example on middleware (schema 'pre' save)
commentSchema.pre('save', function beforeSave(){
    // Reminder: in a "save" middelware, the scope (this) is the entity being saved
    const User = this.model('User');
    return User.get(this.entityData.userIdx)
               .then(() => {
                    ...   
                });
});
```


---

# 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/v5.x+v6.x/entity/methods/model.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.
