Hi,
I'm trying to achieve the following in one transaction, please suggest the feasibility and/or how to do it.
case class GroupList(groups: Array[UUID] = Array())
case class UserList(users: Array[UUID] = Array())
case class Group(groupid: UUID, groupname: String, users: UserList) /* sample Group object in database is : (UUID_HERE, "some group name", {"users":[<CSV of UUID's>]})*/
case class PInfo(id: Long, groups: GroupList, users: UserList) /* sample pinfo object in database is : (1, {"groups":[<CSV of (groupid)UUID's >]}, {"user":[<CSV of (user)UUID's>]})*/
NOW,
I want to do something like, if i pass the id, i want to get all users (including the user within the groups) as one list in minimum number of queries. I've the following in mind but it isn't working
def getUsers(pid: Long) = {
val query = for {
pinfoObj <- slickpinfo.filter(_.id === pid).result.headOption
groupsuserslist <- pinfoObj match {
case Some(pinfo) => slickgroups.filter(_.groupid inSet(pinfo.groups.toList).map(x => x.users).result
case None => slickgroups.filter(_.groupid inSet(<lets say empty list>)).map(x => x.users).result
}
} yield (pinfoObj, groupsuserslist)
db.run(query.result).map (
seqObj => {
var allusers = Array("")
for((pinfo, groupusers) <- seqObj) {
allusers = allusers ++ pinfo.users ++ groupusers
}
}
)
}
what i'm expecting is, if a row in Pinfo has ((id=)1, 2groups (with 5 users in each group), 2users). i want a list of all users (the ones that are directly in userslist and also the users inside each group in groups) as one combined list.
Any help is greatly appreciated.
Thank you.