I have two tables, User
and UserBusinessPartnerIds
User(id, name, email, whatever)
UserBusinessPartnerIds(userId, bpId)
I am trying to retrieve a user and a list of business partner ids.
The following query works fine!
database withSession { implicit session: Session =>
val query = (for {
(user, userBpid) <- Users leftJoin UserBusinessPartners on (_.id is _.userId)
if user.email === email &&
user.password === password &&
user.active === true &&
userBpid.dateFrom < today &&
userBpid.dateTo > today
} yield (user.id, userBpid.bpId.?))
val results = query.list
results.headOption.map( row => User(row._1, email, password, results.map(_._2).flatten.toSet))
}
Granted, the end of the code is heinous; but whatever.
The problem is, I wish to do an OUTER join. So if a user doesn't have a corresponding row to a business partner id in the other table, I still want to get that user.
Any ideas?
edit - Edited the question to actually be correct. I still want to return a user even if they dont have business partner ids associated with them