slick
slick copied to clipboard
Let optional foreign key generator produce outer join
type ID = Array[Byte] // Oracle RAW
object Users extends Table[User]("TB_USER") {
def id = column[ID]("ID",O.PrimaryKey)
def agencyId = column[Option[ID]]("AGENCY_ID")
def inactive = column[Boolean]("INACTIVE", O.Default(false))
def disabled = column[Boolean]("IS_DISABLED", O.Default(true))
def agency = foreignKey("FK_TB_USER_AGENCY_ID",agencyId,Agencies)(_.id.?)
}
object Agencies extends Table[Agency]("TB_AGENCY") {
def id = column[ID]("ID",O.PrimaryKey)
def dataOutOfDate = column[Boolean]("IS_DATA_OUT_OF_DATE")
}
val q = for {
u <- Users
s <- u.agency // agencyId is Option[ID]; let this produce an outer join
} yield (u.disabled, u.inactive, s.dataOutOfDate.?.getOrElse(false))
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
On a second thought - this definitely sounds as something useful on daily basis. Dealing with outer joins is a little bit painful right now.
However I got some doubts if it is really how monadic composition should behave ? I mean if we compare it to other monadic types we use with for comprehension - we would rather expect empty result as soon a we hit first empty value in comprehension, right ?
EDIT: On the second however we obviously operate here on DBIO so whether something is existing or nonexisting option is not relevant here...
+1
+1
+1
+1
@trevorsibanda if you ever feel the itch for hacking on something, here is something that may fall into your ballpark ;)
+1 hi guys, I guess no update here?
+1
+1
+1
+1
PR welcome ;)