你能告诉我为什么我没有得到我期望得到的内部加入吗?
我有以下表格
case class Ability(id: UUID, can: Boolean, verb: String, subject: String, context: String)
object Abilities extends Table[Ability]("abilities"){
def id = column[UUID]("id", O.PrimaryKey)
def can = column[Boolean]("is_can")
def verb = column[String]("verb")
def subject = column[String]("subject")
def context = column[String]("context")
def * = id ~ can ~ verb ~ subject ~ context <> (Ability, Ability.unapply _)
}
case class Role(id: UUID, name : String)
object Roles extends Table[Role]("roles"){
def id = column[UUID]("id", O.PrimaryKey)
def name = column[String]("name")
def * = id ~ name <> (Role, Role.unapply _)
}
// And join table
case class AbilityRelationship(owner_id: UUID, obj_id: UUID, is_role: Boolean)
object AbilitiesMapping extends Table[AbilityRelationship]("abilities_mapping"){
def owner_id = column[UUID]("owner_id")
def obj_id = column[UUID]("obj_id")
def is_role = column[Boolean]("is_role")
def * = owner_id ~ obj_id ~ is_role <> (AbilityRelationship, AbilityRelationship.unapply _)
}
我愿意做的是获取Ability
特定所有者(无论是用户还是角色)的对象列表。因此,按照文档,我为它编写了以下连接查询
val some_id = role.id
val q2 = for {
a <- Abilities
rel <- AbilitiesMapping
if rel.owner_id === some_id.bind
} yield (a)
但q2.selectStatement
返回绝对错误的查询。在select x2."id", x2."is_can", x2."verb", x2."subject", x2."context" from "abilities" x2, "abilities_mapping" x3 where x3."owner_id" = ?
我的情况下。
应该如何实施?
谢谢。