{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/1031","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/1031/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/1031/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/1031/events","html_url":"https://github.com/strongloop/loopback/issues/1031","id":54954815,"number":1031,"title":"Missing ID when POST Multiple models with custom hook","user":{"login":"glesage","id":711580,"avatar_url":"https://avatars.githubusercontent.com/u/711580?v=3","gravatar_id":"","url":"https://api.github.com/users/glesage","html_url":"https://github.com/glesage","followers_url":"https://api.github.com/users/glesage/followers","following_url":"https://api.github.com/users/glesage/following{/other_user}","gists_url":"https://api.github.com/users/glesage/gists{/gist_id}","starred_url":"https://api.github.com/users/glesage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glesage/subscriptions","organizations_url":"https://api.github.com/users/glesage/orgs","repos_url":"https://api.github.com/users/glesage/repos","events_url":"https://api.github.com/users/glesage/events{/privacy}","received_events_url":"https://api.github.com/users/glesage/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-01-20T23:15:14Z","updated_at":"2015-01-29T19:34:50Z","closed_at":null,"body":"No idea how to name this issue properly ;P\r\n\r\nBased on this thread: https://groups.google.com/forum/#!topic/loopbackjs/MjAND8jVFvc\r\n\r\nThe error can be reproduced using this repo: https://github.com/superkhau/zipcode (from @superkhau)\r\n\r\n--> I have a custom hook for beforeCreate for a model which basically checks to see if an object with the same data already exists and return it if it does.\r\n\r\nHere is the hook:\r\n\r\n```\r\nMyModel.beforeCreate = function(next, data)\r\n{\r\n        MyModel.findOne({where: {name: data.name}}, function(err, result)\r\n        {\r\n            if (err) return next(err);\r\n            if (result) return next(null, result);\r\n            return next();\r\n        });\r\n};\r\n```\r\n\r\nAnd when I POST a single model, the response is good: `{ \"name\": \"my_name\", \"id\": 1 }`\r\n\r\nSOOO, when I POST 2 models that don't exist, the response is good: \r\n`[{ \"name\": \"my_name_1\", \"id\": 1 }, { \"name\": \"my_name_2\", \"id\": 2 }]`\r\n\r\nBUT, when I POST 2 models that do exist, the response is:\r\n`[{ \"name\": \"my_name_3\" }, { \"name\": \"my_name_4\" }]`\r\n\r\nAND, when I POST 2 models with one that exists and the other does not, the response is:\r\n`[{ \"name\": \"my_name_4\" }, { \"name\": \"my_name_5\", \"id\": 6 }]`\r\n\r\nSo, when I post multiple models, if the data exists I get NO ID but the others do... Let me know if I'm missing anything (:\r\n\r\nI'm willing to attempt a fix but I have no clue where to look. Feel free to direct me to the various places of Loopback and I'll try to figure something out.\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/72089014","html_url":"https://github.com/strongloop/loopback/issues/1031#issuecomment-72089014","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/1031","id":72089014,"user":{"login":"glesage","id":711580,"avatar_url":"https://avatars.githubusercontent.com/u/711580?v=3","gravatar_id":"","url":"https://api.github.com/users/glesage","html_url":"https://github.com/glesage","followers_url":"https://api.github.com/users/glesage/followers","following_url":"https://api.github.com/users/glesage/following{/other_user}","gists_url":"https://api.github.com/users/glesage/gists{/gist_id}","starred_url":"https://api.github.com/users/glesage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glesage/subscriptions","organizations_url":"https://api.github.com/users/glesage/orgs","repos_url":"https://api.github.com/users/glesage/repos","events_url":"https://api.github.com/users/glesage/events{/privacy}","received_events_url":"https://api.github.com/users/glesage/received_events","type":"User","site_admin":false},"created_at":"2015-01-29T19:34:50Z","updated_at":"2015-01-29T19:34:50Z","body":"oOo perfect thanks!"}}