gpt4 book ai didi

database-design - 如何定义一个 m :n relation with additional attributes in Squeryl?

转载 作者:行者123 更新时间:2023-12-04 18:50:46 25 4
gpt4 key购买 nike

给定一个具有 m:n 关系的旧数据库和该关系的一些附加属性,如何用 squeryl.最后,表格应如下所示:

   +--------------+      +---------------+      +----------------+   | TableA       |      | Rel_A_B       |      | TableB         |   +--------------+ ____ +---------------+ ____ +----------------+   | id: Int      |      | tableA: int   |      | compkey_1: int |   | (more attrs) |      | tableB_1: int |      | compkey_2: int |   +--------------+      | tableB_2: int |      | (more attrs)   |                         | value: Varchar|      +----------------+                         | date: Date    |                         +---------------+

Theres no problem in defining the three tables manually with squeryl. However, as far as I understand the documentation at the moment (0.9.4) there is no possibility to define a many-to-many relationship with additional attributes for the relation.

That's why I defined three tables and two one-to-many relations:


// TableA
class TableA(val id: Int, ...) extends KeyedEntity[Int] {
def this() = this(0, ...)
}

// TableB
class TableB(val compkey1: Int, val compkey2: Int, ...)
extends KeyedEntity[CompositeKey2[Int, Int]] {

def id = CompositeKey2(compkey1, compkey2)
}

// Rel_A_B
class RelAB(val tabA: Int, val tabB1: Int, val tabB2: Int, val value: String,
val date: Date) extends KeyedEntity[CompositeKey3[Int, Int, Int]] {

def id = CompositeKey3(tabA, tabB1, tabB2)
}


定义 TableA 和 RelAB 之间的关系很容易。我使用普通的一对多关系:

val relA =
oneToManyRelation(tableA, relAB).
via((a, r) => a.id === r.tableA)

但我没有看到定义第二个关系的方法。我已经尝试在仅包含 tableB 中的列的关系表(名为 compkeyB)上定义一个额外的复合值,并将其与 tableB 的复合键进行比较,但这不起作用:

val relB =
oneToManyRelation(tableB, relAB).
via((b, r) => b.id === r.compkeyB)

它抛出一个“类型不匹配”异常:
found   : org.squeryl.dsl.ast.LogicalBoolean
required: org.squeryl.dsl.ast.EqualityExpression

任何想法如何解决这个问题?

最佳答案

关于database-design - 如何定义一个 m :n relation with additional attributes in Squeryl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6570882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com