{"action":"created","issue":{"url":"https://api.github.com/repos/pardom/ActiveAndroid/issues/332","repository_url":"https://api.github.com/repos/pardom/ActiveAndroid","labels_url":"https://api.github.com/repos/pardom/ActiveAndroid/issues/332/labels{/name}","comments_url":"https://api.github.com/repos/pardom/ActiveAndroid/issues/332/comments","events_url":"https://api.github.com/repos/pardom/ActiveAndroid/issues/332/events","html_url":"https://github.com/pardom/ActiveAndroid/issues/332","id":55731754,"number":332,"title":"Save->delete->save not working","user":{"login":"lenant","id":2565090,"avatar_url":"https://avatars.githubusercontent.com/u/2565090?v=3","gravatar_id":"","url":"https://api.github.com/users/lenant","html_url":"https://github.com/lenant","followers_url":"https://api.github.com/users/lenant/followers","following_url":"https://api.github.com/users/lenant/following{/other_user}","gists_url":"https://api.github.com/users/lenant/gists{/gist_id}","starred_url":"https://api.github.com/users/lenant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lenant/subscriptions","organizations_url":"https://api.github.com/users/lenant/orgs","repos_url":"https://api.github.com/users/lenant/repos","events_url":"https://api.github.com/users/lenant/events{/privacy}","received_events_url":"https://api.github.com/users/lenant/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-01-28T09:20:53Z","updated_at":"2016-05-04T07:21:57Z","closed_at":null,"body":"For example, this code\r\n\r\n```java\r\nmyModel.save();\r\nLog.d(LOG_TAG, String.valueOf(new Select().from(MyClass.class).execute().size()));\r\nmyModel.delete();\r\nLog.d(LOG_TAG, String.valueOf(new Select().from(MyClass.class).execute().size()));\r\nmyModel.save();\r\nLog.d(LOG_TAG, String.valueOf(new Select().from(MyClass.class).execute().size()));\r\n```\r\n\r\nWill give output\r\n1\r\n0\r\n0\r\nWhile should be \r\n1\r\n0\r\n1\r\n\r\nMost likely it happens because of this part of ```save()``` method:\r\n```java\r\nif (mId == null) {\r\n\tmId = db.insert(mTableInfo.getTableName(), null, values);\r\n}\r\nelse {\r\n\tdb.update(mTableInfo.getTableName(), values, idName+\"=\" + mId, null);\r\n}\r\n```\r\n\r\nAs we can see, if the object has an Id, ActiveAndroid tries to update the row. But the problem is, when model is deleted, the Id is not set to null. So if there is no such a row already, it still tries to update it.\r\n\r\nPossible solution: set mId to null after delete. This is what I currently do via reflection, which is not a nice way to do stuff. \r\nBTW, mId is used in equals/hashCode methods, but since it's not final in the first place, I don't really think it should be. Especially if t would be set to null in delete method."},"comment":{"url":"https://api.github.com/repos/pardom/ActiveAndroid/issues/comments/216764590","html_url":"https://github.com/pardom/ActiveAndroid/issues/332#issuecomment-216764590","issue_url":"https://api.github.com/repos/pardom/ActiveAndroid/issues/332","id":216764590,"user":{"login":"cthulhuplush","id":7002166,"avatar_url":"https://avatars.githubusercontent.com/u/7002166?v=3","gravatar_id":"","url":"https://api.github.com/users/cthulhuplush","html_url":"https://github.com/cthulhuplush","followers_url":"https://api.github.com/users/cthulhuplush/followers","following_url":"https://api.github.com/users/cthulhuplush/following{/other_user}","gists_url":"https://api.github.com/users/cthulhuplush/gists{/gist_id}","starred_url":"https://api.github.com/users/cthulhuplush/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cthulhuplush/subscriptions","organizations_url":"https://api.github.com/users/cthulhuplush/orgs","repos_url":"https://api.github.com/users/cthulhuplush/repos","events_url":"https://api.github.com/users/cthulhuplush/events{/privacy}","received_events_url":"https://api.github.com/users/cthulhuplush/received_events","type":"User","site_admin":false},"created_at":"2016-05-04T07:21:56Z","updated_at":"2016-05-04T07:21:56Z","body":"My solution  was to use this:\r\nhttps://github.com/vicpinm/ActiveAndroidRx\r\n\r\nNo need to use the Rx stuff, just replace gradle depency."}}