gstore-node
v8.x
v8.x
  • Introduction
  • Getting Started
    • Motivation
    • Installation
    • Create a gstore instance
  • Schema
    • About
    • Type validation
    • Value validation
    • Additional properties settings
    • Schema options
    • Joi Schema
    • Methods
      • path()
      • virtual()
    • Custom methods
  • Model
    • Creation
    • Methods
      • GET
      • UPDATE
      • DELETE
      • excludeFromIndexes()
      • key()
      • sanitize()
      • clearCache()
  • Entity
    • Creation
    • Properties
    • Methods
      • SAVE
      • plain()
      • populate()
      • model()
      • datastoreEntity()
      • validate()
  • Queries
    • @google-cloud Query
    • list()
    • findOne()
    • deleteAll()
    • findAround()
  • Populate
  • Middleware (hooks)
    • About
    • Pre hooks
    • Post hooks
  • Cache / Dataloader
    • Dataloader
    • Cache
  • gstore Methods
    • save()
  • Typescript
  • Appendix
    • Error Codes
    • Credits
Powered by GitBook
On this page

Was this helpful?

  1. Entity
  2. Methods

model()

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

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(() => {
                    ...   
                });
});
Previouspopulate()NextdatastoreEntity()

Last updated 6 years ago

Was this helpful?