Custom methods
const blogPostSchema = new Schema({ title: {} });
// Custom method to retrieve all children Text entities
blogPostSchema.methods.texts = function getTexts() {
// the scope (this) is the entity instance
const query = this.model('Text')
.query()
.hasAncestor(this.entityKey);
return query.run();
};
// In your Controller
// You can then call it on an entity instance of BlogPost
const BlogPost = require('../models/blogpost.model');
BlogPost.get(123)
.then((blogEntity) => {
blogEntity.texts()
.then((response) => {
const texts = response[0].entities;
});
});Last updated
Was this helpful?