{"action":"created","issue":{"url":"https://api.github.com/repos/neumino/thinky/issues/90","repository_url":"https://api.github.com/repos/neumino/thinky","labels_url":"https://api.github.com/repos/neumino/thinky/issues/90/labels{/name}","comments_url":"https://api.github.com/repos/neumino/thinky/issues/90/comments","events_url":"https://api.github.com/repos/neumino/thinky/issues/90/events","html_url":"https://github.com/neumino/thinky/issues/90","id":34743103,"number":90,"title":"Model.get() of non-existent id needs better handling","user":{"login":"davewasmer","id":707213,"avatar_url":"https://avatars.githubusercontent.com/u/707213?v=3","gravatar_id":"","url":"https://api.github.com/users/davewasmer","html_url":"https://github.com/davewasmer","followers_url":"https://api.github.com/users/davewasmer/followers","following_url":"https://api.github.com/users/davewasmer/following{/other_user}","gists_url":"https://api.github.com/users/davewasmer/gists{/gist_id}","starred_url":"https://api.github.com/users/davewasmer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davewasmer/subscriptions","organizations_url":"https://api.github.com/users/davewasmer/orgs","repos_url":"https://api.github.com/users/davewasmer/repos","events_url":"https://api.github.com/users/davewasmer/events{/privacy}","received_events_url":"https://api.github.com/users/davewasmer/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2014-06-02T02:38:25Z","updated_at":"2016-03-21T04:50:53Z","closed_at":"2014-06-29T21:40:32Z","body":"Right now, if you try to `Model.get()` with an id that doesn't exist, an error is thrown:\r\n\r\n```javascript\r\n// assume a Post Model\r\nPost.get(\"nonExistingId\").run().error(function(error) {\r\n  // error: Cannot build a new instance of `posts` with `null`.\r\n});\r\n```\r\nSee: https://github.com/neumino/thinky/blob/master/test/query.js#L127\r\n\r\nThis is less than ideal - it's difficult and brittle to test for this condition, and the error message is confusing. I spent a while trying to understand what I was doing wrong, only to realize this is expected behavior.\r\n\r\nIdeally, this wouldn't result in an error condition. It should simply resolve the promise with `null`. At the very least, the error message should be updated to something a bit clearer and easier to test for (e.g. `\"id not found\"` or something similar).\r\n\r\nHappy to take a stab at a PR, but wanted to make sure I wasn't missing anything before I dove in."},"comment":{"url":"https://api.github.com/repos/neumino/thinky/issues/comments/199121644","html_url":"https://github.com/neumino/thinky/issues/90#issuecomment-199121644","issue_url":"https://api.github.com/repos/neumino/thinky/issues/90","id":199121644,"user":{"login":"neumino","id":1461947,"avatar_url":"https://avatars.githubusercontent.com/u/1461947?v=3","gravatar_id":"","url":"https://api.github.com/users/neumino","html_url":"https://github.com/neumino","followers_url":"https://api.github.com/users/neumino/followers","following_url":"https://api.github.com/users/neumino/following{/other_user}","gists_url":"https://api.github.com/users/neumino/gists{/gist_id}","starred_url":"https://api.github.com/users/neumino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neumino/subscriptions","organizations_url":"https://api.github.com/users/neumino/orgs","repos_url":"https://api.github.com/users/neumino/repos","events_url":"https://api.github.com/users/neumino/events{/privacy}","received_events_url":"https://api.github.com/users/neumino/received_events","type":"User","site_admin":false},"created_at":"2016-03-21T04:50:53Z","updated_at":"2016-03-21T04:50:53Z","body":"You can hack something like this:\r\n```\r\nUsers.filter(...).coerceTo(\"ARRAY\").do(function(result) {\r\n  r.branch(\r\n    result.count().eq(0),\r\n    r.error(\"The query did not find a document and returned null.\"),\r\n    result\r\n  )\r\n})\r\n```"}}