gstore-node
Search…
model()
With this method you can access a Model from an entity instance.
1
const BlogPost = require('blog-post.model');
2
const blogEntity = new BlogPost({ title: 'Blog title' });
3
4
blogEntity.save().then(() => {
5
const Image = blogEntity.model('Image'); // access the 'Image' Model
6
const imageEntity = new Image({ uri: 'http://domain.com/image.jpg' });
7
...
8
});
9
10
// Example on middleware (schema 'pre' save)
11
commentSchema.pre('save', function beforeSave(){
12
// Reminder: in a "save" middelware, the scope (this) is the entity being saved
13
const User = this.model('User');
14
return User.get(this.entityData.userIdx)
15
.then(() => {
16
...
17
});
18
});
Copied!
Last modified 2yr ago
Copy link