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

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -