{"action":"created","issue":{"url":"https://api.github.com/repos/requery/requery/issues/825","repository_url":"https://api.github.com/repos/requery/requery","labels_url":"https://api.github.com/repos/requery/requery/issues/825/labels{/name}","comments_url":"https://api.github.com/repos/requery/requery/issues/825/comments","events_url":"https://api.github.com/repos/requery/requery/issues/825/events","html_url":"https://github.com/requery/requery/issues/825","id":366321522,"node_id":"MDU6SXNzdWUzNjYzMjE1MjI=","number":825,"title":"Question: is it possible to use upsert to update/insert without an id?","user":{"login":"AndroidDeveloperLB","id":5357526,"node_id":"MDQ6VXNlcjUzNTc1MjY=","avatar_url":"https://avatars0.githubusercontent.com/u/5357526?v=4","gravatar_id":"","url":"https://api.github.com/users/AndroidDeveloperLB","html_url":"https://github.com/AndroidDeveloperLB","followers_url":"https://api.github.com/users/AndroidDeveloperLB/followers","following_url":"https://api.github.com/users/AndroidDeveloperLB/following{/other_user}","gists_url":"https://api.github.com/users/AndroidDeveloperLB/gists{/gist_id}","starred_url":"https://api.github.com/users/AndroidDeveloperLB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndroidDeveloperLB/subscriptions","organizations_url":"https://api.github.com/users/AndroidDeveloperLB/orgs","repos_url":"https://api.github.com/users/AndroidDeveloperLB/repos","events_url":"https://api.github.com/users/AndroidDeveloperLB/events{/privacy}","received_events_url":"https://api.github.com/users/AndroidDeveloperLB/received_events","type":"User","site_admin":false},"labels":[{"id":286505773,"node_id":"MDU6TGFiZWwyODY1MDU3NzM=","url":"https://api.github.com/repos/requery/requery/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-10-03T12:45:08Z","updated_at":"2018-10-29T08:01:29Z","closed_at":"2018-10-29T06:35:36Z","author_association":"NONE","body":"Supposed I have just 3 fields in a table:\r\n\r\n```\r\n@Entity\r\ninterface TLPhoneToTheme : Parcelable, Persistable {\r\n    @get:Key\r\n    @get:Generated\r\n    var id: Long\r\n    @get:Index(\"phone_index\")\r\n    @get:Column(unique = true, nullable = false)\r\n    var phoneNumber: String\r\n    var themeId: String\r\n}\r\n\r\n```\r\n\r\nSo `phoneNumber` is unique, and `id` is auto-generated.\r\n\r\nWhat if I want to update/add an item to the table? I don't know the id, because for this I would have to use selection, which loses the point of using `upsert`, as I could know for sure that the item exists, and use `update` instead (all in transaction of course) ...\r\n\r\nIs it possible to update/insert without the id in this case?\r\n\r\nI tried this:\r\n\r\n```\r\n            dataStore.withTransaction {\r\n                for (phoneNumber in phoneNumbers) {\r\n                    val phoneToThemeEntity = TLPhoneToThemeEntity()\r\n                    phoneToThemeEntity.phoneNumber = phoneNumber\r\n                    phoneToThemeEntity.themeId = themeId\r\n                    dataStore.upsert(phoneToThemeEntity).blockingGet()\r\n                }\r\n            }.blockingGet()\r\n```\r\n\r\nBut if I use this on items that already exist, it say that ` UNIQUE constraint failed`, even though the point for it being unique is that it will use it for the updating of the items...\r\n\r\nOr I'm using it incorrectly?\r\n"},"comment":{"url":"https://api.github.com/repos/requery/requery/issues/comments/433819309","html_url":"https://github.com/requery/requery/issues/825#issuecomment-433819309","issue_url":"https://api.github.com/repos/requery/requery/issues/825","id":433819309,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzgxOTMwOQ==","user":{"login":"AndroidDeveloperLB","id":5357526,"node_id":"MDQ6VXNlcjUzNTc1MjY=","avatar_url":"https://avatars0.githubusercontent.com/u/5357526?v=4","gravatar_id":"","url":"https://api.github.com/users/AndroidDeveloperLB","html_url":"https://github.com/AndroidDeveloperLB","followers_url":"https://api.github.com/users/AndroidDeveloperLB/followers","following_url":"https://api.github.com/users/AndroidDeveloperLB/following{/other_user}","gists_url":"https://api.github.com/users/AndroidDeveloperLB/gists{/gist_id}","starred_url":"https://api.github.com/users/AndroidDeveloperLB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndroidDeveloperLB/subscriptions","organizations_url":"https://api.github.com/users/AndroidDeveloperLB/orgs","repos_url":"https://api.github.com/users/AndroidDeveloperLB/repos","events_url":"https://api.github.com/users/AndroidDeveloperLB/events{/privacy}","received_events_url":"https://api.github.com/users/AndroidDeveloperLB/received_events","type":"User","site_admin":false},"created_at":"2018-10-29T08:01:29Z","updated_at":"2018-10-29T08:01:29Z","author_association":"NONE","body":"@npurushe So what is suggested? Do I really have to have a transaction, that will make the query and then update/insert myself, manually?\r\n\r\nI thought that maybe Upsert is meant exactly for this...\r\n\r\nIs there maybe another API for this scenario?"}}
{"actor":{"display_login":"AndroidDeveloperLB"}}