node.js - Fetch posts by category with bookshelf.js -
I am using bookshelf.js as my ORM for node. I have 2 models
post = bookshelf. Model Extension ({tableName: 'posts', categories: function ()} This return.belongsToMany ('category');}}); Category = bookshelf.model.extend ({tableName: 'Categories', Post: Function ()} Return to it. Belgstman ('Post');}}); They are related to the categories_pause table, so it's many of the many relationships.
Now I want the user to be able to see all the positions in certain categories. But I just do not want to post all, I should put a score on the page. But I am unable to get the overall posts under the specific category, it always returns the total positions present in the system.
I have tried this code.forge ({id: id}) (). () () () () () () () () () () () ();} But unlike the post table = id Total posts under category identified by this is also possible, or should I make a supporting method which is directly categories_posts table
thanks < P>
category. Forge ({id: id}). Fetch ({withelated: [[Posts: work (Q) {quote ('* AS count')}}}}}). Then (function (total) {console.log (total.Tojon (.) Posts [0]. Count);}); id . will give the correct value of the posts under the category identified.
Comments
Post a Comment