0

I'm playing around with the SailsJS beta and want to know if I can populate associated models via a querystring parameter (by default). I tried

http://localhost:1337/firstModel?populate=secondModel 

but no luck. Is this something I'll have to wire up myself or do I just have the syntax wrong?

--Dave

davepreston
  • 1,260
  • 1
  • 10
  • 20
  • If you're using the blueprint `find` or `findOne` methods, then all associated models should be populated by default. – sgress454 May 02 '14 at 15:05
  • @ScottGress thanks for pointing me in the right direction. I hadn't defined my attributes so they weren't being added. After adding them into the model file all is well. – davepreston May 02 '14 at 15:55
  • @ScottGress sorry to double up on one question, but is there a way to declare which fields I want to come back? especially if all the associations are getting auto-populated, I'm afraid my payload might get pretty big. – davepreston May 02 '14 at 15:57
  • The default blueprint methods will return everything. You can always override those methods to have them return anything you want; just declare a `find` or `findOne` method in `FirstModelController.js`. – sgress454 May 02 '14 at 16:18

0 Answers0