{"action":"created","issue":{"url":"https://api.github.com/repos/lotus/model/issues/248","labels_url":"https://api.github.com/repos/lotus/model/issues/248/labels{/name}","comments_url":"https://api.github.com/repos/lotus/model/issues/248/comments","events_url":"https://api.github.com/repos/lotus/model/issues/248/events","html_url":"https://github.com/lotus/model/pull/248","id":110995403,"number":248,"title":"Check persisted using real existence (instead of id presence)","user":{"login":"aderyabin","id":88676,"avatar_url":"https://avatars.githubusercontent.com/u/88676?v=3","gravatar_id":"","url":"https://api.github.com/users/aderyabin","html_url":"https://github.com/aderyabin","followers_url":"https://api.github.com/users/aderyabin/followers","following_url":"https://api.github.com/users/aderyabin/following{/other_user}","gists_url":"https://api.github.com/users/aderyabin/gists{/gist_id}","starred_url":"https://api.github.com/users/aderyabin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aderyabin/subscriptions","organizations_url":"https://api.github.com/users/aderyabin/orgs","repos_url":"https://api.github.com/users/aderyabin/repos","events_url":"https://api.github.com/users/aderyabin/events{/privacy}","received_events_url":"https://api.github.com/users/aderyabin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/lotus/model/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/lotus/model/milestones/11","html_url":"https://github.com/lotus/model/milestones/v0.5.1","labels_url":"https://api.github.com/repos/lotus/model/milestones/11/labels","id":1330838,"number":11,"title":"v0.5.1","description":"","creator":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"open_issues":7,"closed_issues":1,"state":"open","created_at":"2015-09-30T10:23:08Z","updated_at":"2015-10-14T11:21:13Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2015-10-12T15:15:39Z","updated_at":"2015-10-14T13:13:08Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/lotus/model/pulls/248","html_url":"https://github.com/lotus/model/pull/248","diff_url":"https://github.com/lotus/model/pull/248.diff","patch_url":"https://github.com/lotus/model/pull/248.patch"},"body":"Currently if the entity has `id`,\r\n```ruby\r\nuser = User.new({id: 123, login: 'aderyabin'})\r\n```\r\nthere are no way to persist this entity because `.create` returns nil because id are present and `.update` fails because record in database with this `id` are not exists.\r\n\r\nI suggest to check on persistance by real query to repository. If repository do not have entity with the equal id then and entity are not persisted.\r\n\r\nIt easy to display by example/test:\r\n```ruby\r\nuser = UserRepository.create(User.new(name: 'Don', id: 25))\r\nUserRepository.all.must_include(user)\r\n```\r\n\r\n\r\n// cc @AlfonsoUceda, you asked me to prepare use case and PR. :)"},"comment":{"url":"https://api.github.com/repos/lotus/model/issues/comments/148045294","html_url":"https://github.com/lotus/model/pull/248#issuecomment-148045294","issue_url":"https://api.github.com/repos/lotus/model/issues/248","id":148045294,"user":{"login":"aderyabin","id":88676,"avatar_url":"https://avatars.githubusercontent.com/u/88676?v=3","gravatar_id":"","url":"https://api.github.com/users/aderyabin","html_url":"https://github.com/aderyabin","followers_url":"https://api.github.com/users/aderyabin/followers","following_url":"https://api.github.com/users/aderyabin/following{/other_user}","gists_url":"https://api.github.com/users/aderyabin/gists{/gist_id}","starred_url":"https://api.github.com/users/aderyabin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aderyabin/subscriptions","organizations_url":"https://api.github.com/users/aderyabin/orgs","repos_url":"https://api.github.com/users/aderyabin/repos","events_url":"https://api.github.com/users/aderyabin/events{/privacy}","received_events_url":"https://api.github.com/users/aderyabin/received_events","type":"User","site_admin":false},"created_at":"2015-10-14T13:13:08Z","updated_at":"2015-10-14T13:13:08Z","body":"@joneslee85 . I think that is not good idea too because `.persist` determs method (`.create` or `.update`) by `primary_key` presence."}}