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:

  1. retrieve parents :
    select * user ...
  2. 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.
  3. 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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -