Joining a last activity record
See original GitHub issueI’ve following two entities where I’m trying to get the latest activity for an employee:
interface Activity : Entity<Activity> {
val id: Long
val desc: String
val employee: Employee
val createdAt: LocalDateTime?
companion object : Entity.Factory<Activity>()
}
interface Employee : Entity<Employee> {
var id: Long
var name: String
val latestActivity: Activity?
get() {
var activity = this["latestActivity"]
if (activity == null) {
activity = Activities.asSequenceWithoutReferences().sortedByDescending { it.createdAt }
.filter { it.employeeId eq id }.firstOrNull()
this["latestActivity"] = activity
}
return activity as? Activity
}
companion object : Entity.Factory<Employee>()
}
This 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?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
SQL join: selecting the last records in a one-to-many relationship
Go to the transaction table with multiple records for the same client . Select records of clientID and the latestDate of client's activity...
Read more >Creating a Last Activity Date Formula Field
I'm looking to use Last Activity Date for a report that I am creating for my Sales team, but it does not appear...
Read more >Display Last Activity Date on Object Record Detail Page
The last activity date for an account record is based on all the activities that roll up to the account via the Related...
Read more >How do I capture the LAST activity date and note?
I figured the best way to get my reports to work is to create a field named "Last PR Comment" on my custom...
Read more >Workflow Record Last Date Activity by Team
Workflow Record Last Date Activity by Team. Hello all, Inside the company I work for, the financial team also uses Hubspot to log...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also tried to use a native SQL. In this way, only one query is executed:
Great! I would be very happy to test it out on a real database once ready. Any idea about when it might be available?