{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/1587","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/1587/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/1587/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/1587/events","html_url":"https://github.com/strongloop/loopback/issues/1587","id":100597117,"number":1587,"title":"Before save values inconsistent with relations","user":{"login":"jrschumacher","id":46549,"avatar_url":"https://avatars.githubusercontent.com/u/46549?v=3","gravatar_id":"","url":"https://api.github.com/users/jrschumacher","html_url":"https://github.com/jrschumacher","followers_url":"https://api.github.com/users/jrschumacher/followers","following_url":"https://api.github.com/users/jrschumacher/following{/other_user}","gists_url":"https://api.github.com/users/jrschumacher/gists{/gist_id}","starred_url":"https://api.github.com/users/jrschumacher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrschumacher/subscriptions","organizations_url":"https://api.github.com/users/jrschumacher/orgs","repos_url":"https://api.github.com/users/jrschumacher/repos","events_url":"https://api.github.com/users/jrschumacher/events{/privacy}","received_events_url":"https://api.github.com/users/jrschumacher/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/triage","name":"triage","color":"eb6420"},{"url":"https://api.github.com/repos/strongloop/loopback/labels/waiting","name":"waiting","color":"F5ECCE"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-12T17:47:45Z","updated_at":"2015-08-14T17:14:26Z","closed_at":null,"body":"When considering these two variations `POST /api/conversations` and `POST /api/person/1/conversations` one would expect the *before save* context to be the same however `ctx.instance.personId` does not exist when posting to `/api/conversations` directly. (_Person is an instance of User_)\r\n\r\n**Person.json**\r\n```\r\n{\r\n  \"name\": \"person\",\r\n  \"plural\": \"people\",\r\n  \"base\": \"User\",\r\n  \"relations\": {\r\n    \"conversations\": {\r\n      \"type\": \"hasMany\",\r\n      \"model\": \"conversation\",\r\n      \"foreignKey\": \"\"\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n**conversation.json**\r\n```\r\n{\r\n  \"name\": \"conversation\",\r\n  \"plural\": \"conversations\",\r\n  \"base\": \"PersistedModel\",\r\n  \"idInjection\": true,\r\n  \"relations\": {\r\n    \"person\": {\r\n      \"type\": \"belongsTo\",\r\n      \"model\": \"person\",\r\n      \"foreignKey\": \"\"\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n**conversation.js**\r\n```\r\n  Conversation.observe('before save', function setPersonName (ctx, next) {\r\n\r\n    if(ctx.instance && !ctx.instance.id) {\r\n      ctx.instance.date = !ctx.instance.date ? new Date() : ctx.instance.date;\r\n\r\n      ctx.instance.constructor.relations.person.modelTo\r\n        .findById(ctx.instance.personId, function (err, person) {\r\n          if (err) console.error('Err: ' + err);\r\n          else ctx.instance.personName = person.firstName + ' ' + person.lastName;\r\n\r\n          next();\r\n        });\r\n    }\r\n    else {\r\n      next();\r\n    }\r\n\r\n  });\r\n```\r\n\r\n```\r\n> $ mocha server/test/conversation.test.js                                                                                                                                       \r\n  Add conversation\r\n    POST /api/conversations\r\n*** Err: Error: Model::findById requires the id argument ***\r\n      ✓ should be allowed\r\n      ✓ should have statusCode 200\r\n\r\n  Add conversation\r\n    POST /<dynamic>\r\nDYNAMIC URL: /api/people/2/conversations\r\n      ✓ should be allowed\r\n      ✓ should have statusCode 200\r\n\r\n\r\n  4 passing (1s)\r\n```"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/131185319","html_url":"https://github.com/strongloop/loopback/issues/1587#issuecomment-131185319","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/1587","id":131185319,"user":{"login":"jrschumacher","id":46549,"avatar_url":"https://avatars.githubusercontent.com/u/46549?v=3","gravatar_id":"","url":"https://api.github.com/users/jrschumacher","html_url":"https://github.com/jrschumacher","followers_url":"https://api.github.com/users/jrschumacher/followers","following_url":"https://api.github.com/users/jrschumacher/following{/other_user}","gists_url":"https://api.github.com/users/jrschumacher/gists{/gist_id}","starred_url":"https://api.github.com/users/jrschumacher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrschumacher/subscriptions","organizations_url":"https://api.github.com/users/jrschumacher/orgs","repos_url":"https://api.github.com/users/jrschumacher/repos","events_url":"https://api.github.com/users/jrschumacher/events{/privacy}","received_events_url":"https://api.github.com/users/jrschumacher/received_events","type":"User","site_admin":false},"created_at":"2015-08-14T17:14:26Z","updated_at":"2015-08-14T17:14:26Z","body":"@superkhau I figured out my issue. It was in the remoteMethod I defined I  required an id in a placement not expected. Thanks for the help."}}