Replies: 1 comment
-
val groups = database.groups.filter { ... }.toList()
val groupIds = groups.map { it.id }
val allUsers = database
.from(Users)
.innerJoin(GroupUserRelationships, on = ...)
.where(GroupUserRelationships.groupId.inList(groupIds))
.map { row -> Users.createEntity(row) }
return groups.map { group ->
return Group(
id = group.id,
name = group.name,
members = allUsers.filter { it.groupId == group.id }
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an entity
Groups
and then I have another entityUsers
that belong to those groups. There are three different tables in the database that are associated with these entities. I have:groups_table
users_table
groups_users_relationship
So basically I have group 1. This groups has user A, B, and C associated with that group. So when I join all three tables, I get three separate records, which is to be expected in the SQL. But now comes the part I am struggling with. I want to deserialize them into one single group object that has a list of users.
Here is the query that I am using:
Current Result would look something like this:
Right now I have it returning:
I want to return
Is there an easy way to do this? I have gone through the documentation, and it does not appear like it is explained, but it is possible that I missed it.
I know there is a hacky way that I could do it within kotlin, but I would rather use the framework if it has it built in.
TIA
Beta Was this translation helpful? Give feedback.
All reactions