sql - SailsJS manually populate records using Model.query -
lets have example app http://sailsjs.org/#!/documentation/concepts/orm/associations/onetomany.html
for big reasons(complicated) cannot use model.populate() , i'm stuck in using model.query()
does know how result user.find().populate('pets')
using model.query()
please
thank you
you can waterline adapters populate onetomany:
- retrieve parents :
select * user ...
- retrieve children each parent in 1 query not overload dbms:
select * pet user = user1.id union select * pet user = user2.id union ... union select * pet user = usern.id
. regroup children parentpk(you can use lodash or underscore.js functions it) ex:
users.foreach(function(user){ user.pets = _.filter(pets,function(pet){ return pet.user === user.id; }); });
Comments
Post a Comment