说我有这样的表:
object Leagues : IntIdTable() {
val name = varchar("name", 50).uniqueIndex()
}
object Matches: IntIdTable() {
val game = reference("game", Games)
}
object Users: IntIdTable() {
val name = varchar("name", 50).uniqueIndex()
}
object Bets: IntIdTable() {
val match = reference("match", Matches)
val user = reference("user", Users)
}
Daos属于:
class Bet(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Bet>(Bets)
var match by Bets.match
var user by Bets.user
}
如何为Bets类编写dao或查询,以便我可以查询&#34;给我X玩家在联盟Y&#34;中所做的所有投注。 Bet.find { (user eq X) and (/* what here to get the leagues table ? */) }
答案 0 :(得分:1)
val bets = Bet.wrapRows(
Bets.innerJoin(Matches).innerJoin(Leagues).select {
Bets.user eq X.id and (Leagues.name eq "Y"
}
).toList()