{"action":"created","issue":{"url":"https://api.github.com/repos/emberjs/data/issues/4067","repository_url":"https://api.github.com/repos/emberjs/data","labels_url":"https://api.github.com/repos/emberjs/data/issues/4067/labels{/name}","comments_url":"https://api.github.com/repos/emberjs/data/issues/4067/comments","events_url":"https://api.github.com/repos/emberjs/data/issues/4067/events","html_url":"https://github.com/emberjs/data/issues/4067","id":126286375,"number":4067,"title":"Saving a record removes associations locally","user":{"login":"thejbsmith","id":408512,"avatar_url":"https://avatars.githubusercontent.com/u/408512?v=3","gravatar_id":"","url":"https://api.github.com/users/thejbsmith","html_url":"https://github.com/thejbsmith","followers_url":"https://api.github.com/users/thejbsmith/followers","following_url":"https://api.github.com/users/thejbsmith/following{/other_user}","gists_url":"https://api.github.com/users/thejbsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/thejbsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejbsmith/subscriptions","organizations_url":"https://api.github.com/users/thejbsmith/orgs","repos_url":"https://api.github.com/users/thejbsmith/repos","events_url":"https://api.github.com/users/thejbsmith/events{/privacy}","received_events_url":"https://api.github.com/users/thejbsmith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-01-12T21:56:55Z","updated_at":"2016-02-15T16:29:11Z","closed_at":null,"body":"I have an Ember app using the jsonapi adapter, with a Rails backend using the jsonapi-resources gem.\r\n\r\nIn my ember app, I create a record (with an association), then save the record, and then try to interact with the record. At this point, the association is no longer available locally and must be pulled from another request.\r\nAlthough the association is no longer available locally, the answerId attribute is available locally and has been set correctly since this is just an attribute instead of an association.\r\n```\r\nlet answer = ...;\r\n\r\nlet surveyAnswer = store.createRecord('survey-answer', {\r\n  ...\r\n  answer: answer,\r\n  ...\r\n});\r\n\r\n// surveyAnswer.answer is properly set here\r\n\r\nsurveyAnswer.save()\r\n.then( function(result){\r\n  // result.answer is not available locally and another request must be made to retrieve the answer\r\n}, function(error){\r\n  ...\r\n});\r\n```\r\n\r\nThis Ember app has a very large dataset, so we are trying to minimize requests as much as possible. We have not set up a backend controller to handle an Answer, since they are expected to be side-loaded wherever they are needed.\r\n\r\nIn this instance, why does the returned result no longer have a an answer associated with it? Am I missing something here? Does the save call to the server need to somehow specify what to include when the result is returned?\r\n\r\n-------------------------------\r\n\r\nEmber      : 2.2.0\r\nEmber Data : 2.2.1\r\njQuery     : 1.8.3\r\n\r\n-------------------------------"},"comment":{"url":"https://api.github.com/repos/emberjs/data/issues/comments/184283615","html_url":"https://github.com/emberjs/data/issues/4067#issuecomment-184283615","issue_url":"https://api.github.com/repos/emberjs/data/issues/4067","id":184283615,"user":{"login":"thejbsmith","id":408512,"avatar_url":"https://avatars.githubusercontent.com/u/408512?v=3","gravatar_id":"","url":"https://api.github.com/users/thejbsmith","html_url":"https://github.com/thejbsmith","followers_url":"https://api.github.com/users/thejbsmith/followers","following_url":"https://api.github.com/users/thejbsmith/following{/other_user}","gists_url":"https://api.github.com/users/thejbsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/thejbsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejbsmith/subscriptions","organizations_url":"https://api.github.com/users/thejbsmith/orgs","repos_url":"https://api.github.com/users/thejbsmith/repos","events_url":"https://api.github.com/users/thejbsmith/events{/privacy}","received_events_url":"https://api.github.com/users/thejbsmith/received_events","type":"User","site_admin":false},"created_at":"2016-02-15T16:29:10Z","updated_at":"2016-02-15T16:29:10Z","body":"There seems to be a difference in how relationships are handled in different situations.\r\n\r\nFor Example:\r\n\r\n**Saving a Record**\r\n```\r\nlet surveyAnswer = store.createRecord('survey-answer', {\r\n  ...\r\n  answer: answer,\r\n  ...\r\n});\r\n\r\nsurveyAnswer.save\r\n// Returns only relationship links\r\n```\r\n`surveyAnswer.get('answers')` does not return any answers.\r\nWhen the data is received from the server, the relationships are wiped out and set to what was returned by the server.\r\n\r\n**Fetching Records**\r\n```\r\nlet originalSurveyAnswer = store.query('survey-answer', { filter: { id: 1 }, include: 'answers' } );\r\n// Returns relationship links and data\r\n\r\nlet newSurveyAnswer = store.findRecord('survey-answer', 1);\r\n// Returns only relationship links\r\n```\r\n`newSurveyAnswer.get('answers')` does return answers.\r\nWhen the data is received from the server for originalSurveyAnswer, the answers are included by links and data, so the answers are available.\r\nWhen the data is received from the server for newSurveyAnswer, only the relationship links are provided. BUT since the answers were already associated by the call for originalSurveyAnswer, newSurveyAnswer does have answers.\r\n\r\nIt seems that on save calls, the relationship data is replaced with what is returned by the server, but on fetch calls the relationship data is merged with what is returned from the server.\r\n\r\nWhy are the relationships handled differently in each of these situations? "}}