{"action":"created","issue":{"url":"https://api.github.com/repos/bookshelf/bookshelf/issues/1636","repository_url":"https://api.github.com/repos/bookshelf/bookshelf","labels_url":"https://api.github.com/repos/bookshelf/bookshelf/issues/1636/labels{/name}","comments_url":"https://api.github.com/repos/bookshelf/bookshelf/issues/1636/comments","events_url":"https://api.github.com/repos/bookshelf/bookshelf/issues/1636/events","html_url":"https://github.com/bookshelf/bookshelf/issues/1636","id":250865439,"number":1636,"title":"Fail to update a model relation","user":{"login":"cmallet","id":7803718,"avatar_url":"https://avatars1.githubusercontent.com/u/7803718?v=4","gravatar_id":"","url":"https://api.github.com/users/cmallet","html_url":"https://github.com/cmallet","followers_url":"https://api.github.com/users/cmallet/followers","following_url":"https://api.github.com/users/cmallet/following{/other_user}","gists_url":"https://api.github.com/users/cmallet/gists{/gist_id}","starred_url":"https://api.github.com/users/cmallet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmallet/subscriptions","organizations_url":"https://api.github.com/users/cmallet/orgs","repos_url":"https://api.github.com/users/cmallet/repos","events_url":"https://api.github.com/users/cmallet/events{/privacy}","received_events_url":"https://api.github.com/users/cmallet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-08-17T08:24:15Z","updated_at":"2017-08-17T21:09:47Z","closed_at":null,"body":"Hello\r\n\r\nI guess I'm totally out of line but my problem seems very simple.\r\n\r\nI have a basic one to many relation, and I need to update the object belonging to another one.\r\n\r\n```\r\nvar Leg = bookshelf.Model.extend({\r\n   tableName: 'leg',\r\n   idAttribute: 'legId',\r\n\r\n  aircraft: function () {\r\n    return this.belongsTo(Aircraft, 'aircraftId');\r\n  }\r\n}\r\n```\r\nI have a Leg fetched from db, all the aircrafts fetched from database, and I just want to update the aircraft in a leg.\r\n\r\nWhen I perform\r\n\r\n```\r\nleg.set('aircraft', aircraft);\r\n```\r\nor\r\n\r\n`leg.related('aircraft').set(aircraft);`\r\nThe Object returned by\r\n\r\n`leg.related('aircraft')`\r\nis actually not the same as aircraft. It is not updated and I still have the previous one\r\n\r\nWhat am I missing in the API ?\r\n\r\nThanks"},"comment":{"url":"https://api.github.com/repos/bookshelf/bookshelf/issues/comments/323195181","html_url":"https://github.com/bookshelf/bookshelf/issues/1636#issuecomment-323195181","issue_url":"https://api.github.com/repos/bookshelf/bookshelf/issues/1636","id":323195181,"user":{"login":"cmallet","id":7803718,"avatar_url":"https://avatars1.githubusercontent.com/u/7803718?v=4","gravatar_id":"","url":"https://api.github.com/users/cmallet","html_url":"https://github.com/cmallet","followers_url":"https://api.github.com/users/cmallet/followers","following_url":"https://api.github.com/users/cmallet/following{/other_user}","gists_url":"https://api.github.com/users/cmallet/gists{/gist_id}","starred_url":"https://api.github.com/users/cmallet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmallet/subscriptions","organizations_url":"https://api.github.com/users/cmallet/orgs","repos_url":"https://api.github.com/users/cmallet/repos","events_url":"https://api.github.com/users/cmallet/events{/privacy}","received_events_url":"https://api.github.com/users/cmallet/received_events","type":"User","site_admin":false},"created_at":"2017-08-17T21:09:47Z","updated_at":"2017-08-17T21:09:47Z","body":"Yes, I want to change the aircraft within a given leg.\r\nI fetched them both (actually I have all the aircrafts), and i want to replace the leg aircraft. \r\nBasically I would assume I can set it, just like changing an attribute by calling `aircraft.set('attr', value)` . But relations seems to behave differently.\r\n\r\nNow I don't know if that's appropriate, but I don't change to update anything in the database yet. I want to work with this modified leg before saving it, and manipulate it by calling `leg.related('aircraft')`. I need this to return the current aircraft, updated or not.. \r\n\r\nHope this makes it clearer, thank you"}}
{"actor":{"display_login":"cmallet"}}