{"action":"created","issue":{"url":"https://api.github.com/repos/requery/requery/issues/241","repository_url":"https://api.github.com/repos/requery/requery","labels_url":"https://api.github.com/repos/requery/requery/issues/241/labels{/name}","comments_url":"https://api.github.com/repos/requery/requery/issues/241/comments","events_url":"https://api.github.com/repos/requery/requery/issues/241/events","html_url":"https://github.com/requery/requery/issues/241","id":168479231,"number":241,"title":"toSelfObservable does emit on relation update, but actual value is not updated.","user":{"login":"yshrsmz","id":654889,"avatar_url":"https://avatars.githubusercontent.com/u/654889?v=3","gravatar_id":"","url":"https://api.github.com/users/yshrsmz","html_url":"https://github.com/yshrsmz","followers_url":"https://api.github.com/users/yshrsmz/followers","following_url":"https://api.github.com/users/yshrsmz/following{/other_user}","gists_url":"https://api.github.com/users/yshrsmz/gists{/gist_id}","starred_url":"https://api.github.com/users/yshrsmz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yshrsmz/subscriptions","organizations_url":"https://api.github.com/users/yshrsmz/orgs","repos_url":"https://api.github.com/users/yshrsmz/repos","events_url":"https://api.github.com/users/yshrsmz/events{/privacy}","received_events_url":"https://api.github.com/users/yshrsmz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-30T17:58:19Z","updated_at":"2016-08-01T06:55:55Z","closed_at":null,"body":"tested on 1.0.0-rc2.\r\n\r\nI have following three entities\r\n\r\n```kotlin\r\n@Entity\r\ninterface CredentialDB : Persistable {\r\n\r\n  @get:Key\r\n  val key: String\r\n\r\n  @get:[OneToOne(cascade = arrayOf(CascadeAction.SAVE)) ForeignKey]\r\n  val token: TokenDB\r\n\r\n  @get:[OneToOne(cascade = arrayOf(CascadeAction.SAVE)) ForeignKey]\r\n  val user: UserDB\r\n}\r\n```\r\n\r\n```kotlin\r\n@Entity\r\ninterface TokenDB : Persistable {\r\n\r\n  @get:Key\r\n  val key: String\r\n\r\n  val secretKey: String\r\n}\r\n```\r\n\r\n```kotlin\r\n@Entity\r\ninterface UserDB : Persistable {\r\n\r\n  @get:[Key]\r\n  val id: UUID\r\n\r\n  val name: String\r\n\r\n  val following: Int\r\n\r\n  val likes: Long\r\n\r\n  val defaultPostFormat: String\r\n}\r\n```\r\n\r\n\r\nand following method\r\n\r\n```kotlin\r\noverride fun read(spec: Spec): Observable<List<Credential>> {\r\n    checkSpec(spec)\r\n\r\n    val query: Result<CredentialDBEntity>\r\n    if (spec.all) {\r\n      query = entityStore.select(CredentialDBEntity::class.java).get()\r\n    } else {\r\n      query = entityStore.select(CredentialDBEntity::class.java)\r\n          .where(CredentialDBEntity.KEY.eq(spec.key)).get()\r\n    }\r\n    return query.toSelfObservable()\r\n        .filter { it.count() > 0 }\r\n        .flatMap {\r\n          Observable.from(it)\r\n              .map { toModel(it) }\r\n              .toList()\r\n        }\r\n  }\r\n```\r\n\r\nand here is a test case\r\n\r\n\r\n```kotlin\r\n@Test\r\n  fun read() {\r\n    val token = Token(key = \"this_is_key\", secretKey = \"this_is_secret_key\")\r\n    val user = User(following = 100, defaultPostFormat = PostFormat.MARKDOWN, name = \"test_user\", likes = 200)\r\n    val credential = Credential(token, user)\r\n\r\n    val credential2 = credential.copy(user = user.copy(likes = 300))\r\n\r\n    val entity1 = toEntity(credential)\r\n\r\n    val ts = TestSubscriber.create<List<Credential>>()\r\n\r\n    entityStore.insert(entity1).subscribe()\r\n\r\n    repository.read(CredentialLocalRepository.Spec(key = token.key))\r\n        .subscribe(ts)\r\n\r\n    ts.assertNotCompleted()\r\n    ts.assertValue(listOf(credential))\r\n\r\n    val entity2 = toEntity(credential2)\r\n    entityStore.update(entity2).subscribe()\r\n\r\n    ts.assertNotCompleted()\r\n    ts.assertValues(listOf(credential), listOf(credential2)) // test fails here!\r\n    // below passes, btw\r\n    //ts.assertValues(listOf(credential), listOf(credential1))\r\n  }\r\n```\r\n\r\n`toModel` is a method to convert entity to kotlin data class, and `toEntity` vice versa.\r\n\r\nbtw, running method below gets updated value correctly. `entityStore.select(CredentialDBEntity::class.java).where(CredentialDBEntity.KEY.eq(token.key)).get().toList()` "},"comment":{"url":"https://api.github.com/repos/requery/requery/issues/comments/236503296","html_url":"https://github.com/requery/requery/issues/241#issuecomment-236503296","issue_url":"https://api.github.com/repos/requery/requery/issues/241","id":236503296,"user":{"login":"npurushe","id":4143434,"avatar_url":"https://avatars.githubusercontent.com/u/4143434?v=3","gravatar_id":"","url":"https://api.github.com/users/npurushe","html_url":"https://github.com/npurushe","followers_url":"https://api.github.com/users/npurushe/followers","following_url":"https://api.github.com/users/npurushe/following{/other_user}","gists_url":"https://api.github.com/users/npurushe/gists{/gist_id}","starred_url":"https://api.github.com/users/npurushe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/npurushe/subscriptions","organizations_url":"https://api.github.com/users/npurushe/orgs","repos_url":"https://api.github.com/users/npurushe/repos","events_url":"https://api.github.com/users/npurushe/events{/privacy}","received_events_url":"https://api.github.com/users/npurushe/received_events","type":"User","site_admin":false},"created_at":"2016-08-01T06:55:54Z","updated_at":"2016-08-01T06:55:54Z","body":"Ok. Looks like you are creating a self observable against `CredentialDB` when you insert the first time you insert a Credential, User and Token. That will trigger your observable with `credential`. Then you change the user like value when you update `credential2 `. For that update only the user table should be changed not any other table, so it won't emit for `CredentialDB`'s observable."}}
{"actor":{"display_login":"npurushe"}}