.populateAll( [query] )

Purpose

This chainable method is used between .find()/.update() and .exec() in order to retrieve records associated with the model being queried. All known associations of your model will be populated and the query will be applied to each of them.

Overview

Parameters

Description Accepted Data Types Required ?
1 Query object No

Example Usage

  1. User.find({name:'Mike'}).exec(function(e,r){
  2. console.log(r[0].toJSON())
  3. })
  4. /*
  5. { name: 'Mike',
  6. age: 16,
  7. createdAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  8. updatedAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  9. id: 7 }
  10. */
  11. User.find({name:'Mike'}).populateAll().exec(function(e,r){
  12. console.log(r[0].toJSON())
  13. });
  14. /*
  15. { poneys:
  16. [ { name: 'Twinky',
  17. color: 'brown',
  18. id: 1,
  19. createdAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  20. updatedAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST) } ],
  21. pets:
  22. [ { name: 'Pinkie Pie',
  23. color: 'pink',
  24. id: 7,
  25. createdAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  26. updatedAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST) },
  27. { name: 'Rainbow Dash',
  28. color: 'blue',
  29. id: 8,
  30. createdAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  31. updatedAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST) },
  32. { name: 'Applejack',
  33. color: 'orange',
  34. id: 9,
  35. createdAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  36. updatedAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST) } ],
  37. name: 'Mike',
  38. age: 16,
  39. createdAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  40. updatedAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  41. id: 7 }
  42. */
  43. User.find({name:'Mike'}).populateAll({color:'pink'}).exec(function(e,r){
  44. console.log(r[0].toJSON())
  45. });
  46. /*
  47. { pets:
  48. [ { name: 'Pinkie Pie',
  49. color: 'pink',
  50. id: 7,
  51. createdAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  52. updatedAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST) }],
  53. name: 'Mike',
  54. age: 16,
  55. createdAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  56. updatedAt: Wed Feb 12 2014 18:06:50 GMT-0600 (CST),
  57. id: 7 }
  58. */

Notes

Any string arguments passed must be the primary key of the record.