1

I am working on a project using SailsJS as backend. In its waterline data model, I defined a model Abc. Abc has a property, images, which is a collection. Each value in images is an id of an instance of a different Image model.

When I post an object to '/abc', with images property of the object set to be a string containing ids of images, such as '1,2', the Abc instance creation process works, as shown by results of subsequent GET requests.

In current settings, when the 'POST /abc' process works, the newly created abc instance will be returned as server response.

POST /abc?property1=' '&property2=' '&images='1,2'...

server response:

{ id: 1000, property1=' ', property2=' ', ....}

However, server response does not contain populated images properties.

How can I request server to return populated images property for the newly created abc instance in its response?

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
windchime
  • 1,253
  • 16
  • 37
  • sails usually does return you the populated relations by default, or let's say it returns the same response as when you do a `GET`. You can inspect the code for the default [`create` blueprint](https://github.com/balderdashy/sails/tree/master/lib/hooks/blueprints/actions), and perhaps you can try [overriding it](http://stackoverflow.com/questions/22273789/crud-blueprint-overriding-in-sailsjs). – r0hitsharma Jan 29 '15 at 13:37

1 Answers1

0

You're probably should define afterCreate callback in your model. It is invoked each time when you use Model.create() with newly created record as first parameter. You can specify there anything that you want your model to return when you create new record.

Boris Zagoruiko
  • 12,705
  • 15
  • 47
  • 79