I have seen lots of very similar questions but don't give a direct answer for actually waiting. I have a script based on Bookshelf.js;
var Product = bookshelf.Model.extend({
tableName: 'amazon_products',
hasTimestamps: true,
virtuals: { //https://github.com/bookshelf/bookshelf/wiki/Plugin:-Virtuals
hasSiteProduct: function() {
var product_references = this.related('siteProductsReferences').fetch()
return product_references.length;
}
}
});
I have setup a virtual property that will simply count the OneToMany relations of the model and return the count. But in this case it looks like this.related('siteProductsReferences').fetch()
has to take sometime before returning a response. The this.related('siteProductsReferences').fetch()
also has a promise that can look like this;
this.related('siteProductsReferences').fetch().then(function(result) {
// ...
});
I am building this to be returned via an API. If I just add return this.related('siteProductsReferences').fetch()
to the method I get a full l get;
,"hasSiteProduct":{"isFulfilled":false,"isRejected":false}
So clearly the callback has not finished.