javascript - Sails.js query on an associated value -


i'm using sails.js version 0.10.0-rc4. models using sails-mysql.

i'm trying query model has "one-to-many" association model (the query happening on "many" side).

it looks this:

post.find()     .where({ category: category_id })     .populate("category")     .exec( ... ) 

this gives me empty array when leave out .populate("category") correct result set.

i know leave .populate("category") out , fetch each correlating category object separately, i'm wondering if there's better solution problem.

it's not 100% clear you're trying here. if goal filter categories populated on post, can do:

post.find()     .populate("category", {where: { category: category_id }})     .exec( ... ) 

if want retrieve posts category, do:

category.findone(category_id)         .populate("posts")         .exec(function(e, c) {console.log(c.posts);}) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -