{"action":"created","issue":{"url":"https://api.github.com/repos/derbyjs/racer/issues/216","labels_url":"https://api.github.com/repos/derbyjs/racer/issues/216/labels{/name}","comments_url":"https://api.github.com/repos/derbyjs/racer/issues/216/comments","events_url":"https://api.github.com/repos/derbyjs/racer/issues/216/events","html_url":"https://github.com/derbyjs/racer/issues/216","id":60863520,"number":216,"title":"query immediately after set gives unexpected empty result","user":{"login":"enjalot","id":96189,"avatar_url":"https://avatars.githubusercontent.com/u/96189?v=3","gravatar_id":"","url":"https://api.github.com/users/enjalot","html_url":"https://github.com/enjalot","followers_url":"https://api.github.com/users/enjalot/followers","following_url":"https://api.github.com/users/enjalot/following{/other_user}","gists_url":"https://api.github.com/users/enjalot/gists{/gist_id}","starred_url":"https://api.github.com/users/enjalot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enjalot/subscriptions","organizations_url":"https://api.github.com/users/enjalot/orgs","repos_url":"https://api.github.com/users/enjalot/repos","events_url":"https://api.github.com/users/enjalot/events{/privacy}","received_events_url":"https://api.github.com/users/enjalot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-12T17:48:42Z","updated_at":"2015-03-13T00:50:31Z","closed_at":null,"body":"from a coworker:\r\n\r\nI was doing a query immediately after doing a set, and the query wasn't picking up on the changes. It made sense after I was explained what was going on behind the scenes, but it's a subtle gotcha that's not documented anywhere.\r\n\r\n```\r\nmodel.set('users.42.foo', 'abc');\r\nquery = model.query('users', {foo: 'abc'};\r\nmodel.fetch(query, function(err) {\r\n  console.log(query.get());  // Query results are empty...\r\n  console.log(model.get('users.42.foo'));  // But this will be 'abc'!\r\n});\r\n```\r\n\r\nthis is because local operations haven't been flushed. we either want to fix this experience or document it well."},"comment":{"url":"https://api.github.com/repos/derbyjs/racer/issues/comments/78721667","html_url":"https://github.com/derbyjs/racer/issues/216#issuecomment-78721667","issue_url":"https://api.github.com/repos/derbyjs/racer/issues/216","id":78721667,"user":{"login":"ericyhwang","id":6915076,"avatar_url":"https://avatars.githubusercontent.com/u/6915076?v=3","gravatar_id":"","url":"https://api.github.com/users/ericyhwang","html_url":"https://github.com/ericyhwang","followers_url":"https://api.github.com/users/ericyhwang/followers","following_url":"https://api.github.com/users/ericyhwang/following{/other_user}","gists_url":"https://api.github.com/users/ericyhwang/gists{/gist_id}","starred_url":"https://api.github.com/users/ericyhwang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericyhwang/subscriptions","organizations_url":"https://api.github.com/users/ericyhwang/orgs","repos_url":"https://api.github.com/users/ericyhwang/repos","events_url":"https://api.github.com/users/ericyhwang/events{/privacy}","received_events_url":"https://api.github.com/users/ericyhwang/received_events","type":"User","site_admin":false},"created_at":"2015-03-13T00:50:31Z","updated_at":"2015-03-13T00:50:31Z","body":"Said coworker here!\r\n\r\nThe \"workaround\" for the issue was to either use the optional callback to `model.set`, which is called when the operation completes:\r\n\r\n    model.set('users.42.foo', 'abc', function(err) {\r\n      query = model.query('users', {foo: 'abc'};\r\n      model.fetch(query, function(err) {\r\n        console.log(query.get());  // Query will be up-to-date.\r\n      });\r\n    });\r\n\r\nOr, with multiple edit operations, another thing that seemed to work was using the (currently undocumented) `model.whenNothingPending`:\r\n\r\n    model.set('users.42.foo', 'abc');\r\n    model.set('users.43.foo', 'abc');\r\n    model.whenNothingPending(function(err) {\r\n      query = model.query('users', {foo: 'abc'};\r\n      model.fetch(query, function(err) {\r\n        console.log(query.get());  // Query will be up-to-date.\r\n      });\r\n    });\r\n\r\nBeing able to do queries in the client would be really neat, but then your query results would depend on what documents you have loaded in the client. For instance, there could be lots of user documents with `{foo: 'abc'}` that you don't have locally, so the query results on your local data versus the remote data would be different."}}