{"action":"created","issue":{"url":"https://api.github.com/repos/vincentlauvlwj/Ktorm/issues/45","repository_url":"https://api.github.com/repos/vincentlauvlwj/Ktorm","labels_url":"https://api.github.com/repos/vincentlauvlwj/Ktorm/issues/45/labels{/name}","comments_url":"https://api.github.com/repos/vincentlauvlwj/Ktorm/issues/45/comments","events_url":"https://api.github.com/repos/vincentlauvlwj/Ktorm/issues/45/events","html_url":"https://github.com/vincentlauvlwj/Ktorm/issues/45","id":495327701,"node_id":"MDU6SXNzdWU0OTUzMjc3MDE=","number":45,"title":"Joining a last activity record","user":{"login":"ashokgelal","id":401055,"node_id":"MDQ6VXNlcjQwMTA1NQ==","avatar_url":"https://avatars0.githubusercontent.com/u/401055?v=4","gravatar_id":"","url":"https://api.github.com/users/ashokgelal","html_url":"https://github.com/ashokgelal","followers_url":"https://api.github.com/users/ashokgelal/followers","following_url":"https://api.github.com/users/ashokgelal/following{/other_user}","gists_url":"https://api.github.com/users/ashokgelal/gists{/gist_id}","starred_url":"https://api.github.com/users/ashokgelal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashokgelal/subscriptions","organizations_url":"https://api.github.com/users/ashokgelal/orgs","repos_url":"https://api.github.com/users/ashokgelal/repos","events_url":"https://api.github.com/users/ashokgelal/events{/privacy}","received_events_url":"https://api.github.com/users/ashokgelal/received_events","type":"User","site_admin":false},"labels":[{"id":1145410069,"node_id":"MDU6TGFiZWwxMTQ1NDEwMDY5","url":"https://api.github.com/repos/vincentlauvlwj/Ktorm/labels/question","name":"question","color":"d876e3","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2019-09-18T16:19:28Z","updated_at":"2019-09-20T07:26:31Z","closed_at":null,"author_association":"NONE","body":"I've following two entities where I'm trying to get the latest activity for an employee:\r\n\r\n```kotlin\r\ninterface Activity : Entity<Activity> {\r\n    val id: Long\r\n    val desc: String\r\n    val employee: Employee\r\n    val createdAt: LocalDateTime?\r\n    companion object : Entity.Factory<Activity>()\r\n}\r\n\r\ninterface Employee : Entity<Employee> {\r\n    var id: Long\r\n    var name: String\r\n    \r\n    val latestActivity: Activity?\r\n        get() {\r\n            var activity = this[\"latestActivity\"]\r\n            if (activity == null) {\r\n                activity = Activities.asSequenceWithoutReferences().sortedByDescending { it.createdAt }\r\n                    .filter { it.employeeId eq id }.firstOrNull()\r\n                this[\"latestActivity\"] = activity\r\n            }\r\n            return activity as? Activity\r\n        }\r\n    companion object : Entity.Factory<Employee>()\r\n}\r\n```\r\n\r\nThis all works great but unfortunately for each employee getting the `latestActivity` is an extra query. What's the best way to fetch Employees and have it returned with `latestActivity` joined?"},"comment":{"url":"https://api.github.com/repos/vincentlauvlwj/Ktorm/issues/comments/533441897","html_url":"https://github.com/vincentlauvlwj/Ktorm/issues/45#issuecomment-533441897","issue_url":"https://api.github.com/repos/vincentlauvlwj/Ktorm/issues/45","id":533441897,"node_id":"MDEyOklzc3VlQ29tbWVudDUzMzQ0MTg5Nw==","user":{"login":"vincentlauvlwj","id":10897214,"node_id":"MDQ6VXNlcjEwODk3MjE0","avatar_url":"https://avatars1.githubusercontent.com/u/10897214?v=4","gravatar_id":"","url":"https://api.github.com/users/vincentlauvlwj","html_url":"https://github.com/vincentlauvlwj","followers_url":"https://api.github.com/users/vincentlauvlwj/followers","following_url":"https://api.github.com/users/vincentlauvlwj/following{/other_user}","gists_url":"https://api.github.com/users/vincentlauvlwj/gists{/gist_id}","starred_url":"https://api.github.com/users/vincentlauvlwj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vincentlauvlwj/subscriptions","organizations_url":"https://api.github.com/users/vincentlauvlwj/orgs","repos_url":"https://api.github.com/users/vincentlauvlwj/repos","events_url":"https://api.github.com/users/vincentlauvlwj/events{/privacy}","received_events_url":"https://api.github.com/users/vincentlauvlwj/received_events","type":"User","site_admin":false},"created_at":"2019-09-20T07:26:31Z","updated_at":"2019-09-20T07:26:31Z","author_association":"OWNER","body":"Thank you. This is a good article. In fact, I also have a plan to support subqueries. The final usage should be similar to that in this article."}}
{"actor":{"display_login":"vincentlauvlwj"}}