{"action":"closed","issue":{"url":"https://api.github.com/repos/balderdashy/waterline-docs/issues/16","labels_url":"https://api.github.com/repos/balderdashy/waterline-docs/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/balderdashy/waterline-docs/issues/16/comments","events_url":"https://api.github.com/repos/balderdashy/waterline-docs/issues/16/events","html_url":"https://github.com/balderdashy/waterline-docs/issues/16","id":40702760,"number":16,"title":"Question about associations and populate","user":{"login":"Kikobeats","id":2096101,"avatar_url":"https://avatars.githubusercontent.com/u/2096101?v=3","gravatar_id":"","url":"https://api.github.com/users/Kikobeats","html_url":"https://github.com/Kikobeats","followers_url":"https://api.github.com/users/Kikobeats/followers","following_url":"https://api.github.com/users/Kikobeats/following{/other_user}","gists_url":"https://api.github.com/users/Kikobeats/gists{/gist_id}","starred_url":"https://api.github.com/users/Kikobeats/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kikobeats/subscriptions","organizations_url":"https://api.github.com/users/Kikobeats/orgs","repos_url":"https://api.github.com/users/Kikobeats/repos","events_url":"https://api.github.com/users/Kikobeats/events{/privacy}","received_events_url":"https://api.github.com/users/Kikobeats/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-08-20T14:17:05Z","updated_at":"2015-03-23T12:44:26Z","closed_at":"2015-03-23T12:44:26Z","body":"I like `populate` but I encounter a scenario when I need it and is not possible.\r\n\r\nWhen you `create` a new model and this model have a association (whatever kind of association) the `create` method return the new object but not return only with the FK of the association. So populate doesn't work when you created news instances.\r\n\r\nI fixed it doing a find of the new instance with `populate` and return it, but I'm think that is not efficient.\r\n\r\nIs it possible any better solution?\r\n\r\nIn my particular case, I need that the return contain the model association values (in HTTP and sockets)\r\n\r\nMy solution:\r\n\r\n```\r\n# Create new instance of model using data from params\r\n  Model.create(data).populateAll().exec (err, newInstance) ->\r\n\r\n    # Differentiate between waterline-originated validation errors\r\n    # and serious underlying issues. Respond with badRequest if a\r\n    # validation error is encountered, w/ validation info.\r\n    return res.negotiate(err)  if err\r\n\r\n    # Use find method to return the model for the populate option\r\n    Model.findOne(newInstance.id).populateAll().exec (err, newInstance) ->\r\n\r\n      # If we have the pubsub hook, use the model class's publish method\r\n      # to notify all subscribers about the created item\r\n      if req._sails.hooks.pubsub\r\n        if req.isSocket\r\n          Model.subscribe req, newInstance\r\n          Model.introduce newInstance\r\n        Model.publishCreate newInstance, not req.options.mirror and req\r\n\r\n      # Send JSONP-friendly response if it's supported\r\n      # (HTTP 201: Created)\r\n\r\n      # Change the id for user.email\r\n      res.status 201\r\n      res.ok newInstance\r\n\r\n```"}}