I'm building a webapp on node.js (sails) with waterline (using mysql adapter).
I've managed to get relationships working like this:
//Post.js attributes
post_statistics: {
collection: 'postStatistics',
via: 'post'
}
I can easily find the relationship records with the line:
var query = {user:userId}; // Just filtering by the user
query.is_public = Post.POSTS_ONLY_ACTIVE; // Only showing active posts, boolean
query.select = ['id','title','content']; // id is only needed for me to get the join working
Post.find(query).populate('post_statistics').exec(cb);
Everything works fine but I need to only select specific fields from post_statistics. This does not seem to do anything, though, I'd expect it to work:
Post.find(query).populate('post_statistics',{select:['post','user','id']}).exec(cb);
Adding the field names to the initial select is even worse since the fields already target the post table.
Any sane way to make this work or am I going to have to write the whole query?
Aucun commentaire:
Enregistrer un commentaire