0
UPDATE:改變了樣本,以反映我目前的狀況電梯映射 - 特質與一對多映射
相當新的提升,我想創建我的應用程序的模型。由於我想保持DRY精神,所以我想使用trait mixins來指定模型中的一些字段。舉例來說,我有一個Person
特質,我MIXIN我Employee
類:
trait Person[T <: LongKeyedMapper[T]] extends LongKeyedMapper[T]{
self: T =>
object firstName extends MappedString[T](this, 50)
object lastName extends MappedString[T](this, 50)
object civicRegNumber extends MappedString[T](this, 12)
}
class Employee extends IdPK with OneToMany[Long, Employee] with Person[Employee] {
def getSingleton = Employee
object contactInfos extends MappedOneToMany(EmployeeContactInfo, EmployeeContactInfo.person)
}
object Employee extends Employee with LongKeyedMetaMapper[Employee]
可以看出我有很多在員工一個映射contactInfos。它看起來像:
trait PersonContactInfo[T <: LongKeyedMapper[T],P <: Person[P]] extends LongKeyedMapper[T] {
self: T =>
object email extends MappedEmail[T](this, 80)
def personMeta:P with LongKeyedMetaMapper[P]
object person extends LongMappedMapper[T,P](this, personMeta)
}
class EmployeeContactInfo extends IdPK with PersonContactInfo[EmployeeContactInfo, Employee] {
def getSingleton = EmployeeContactInfo
val personMeta = Employee
}
object EmployeeContactInfo extends EmployeeContactInfo with LongKeyedMetaMapper[EmployeeContactInfo]
這似乎是工作,但我想移動的對象contactInfos到我Person
特質。然而,我無法弄清楚如何實現這個...是否可以繼承OneToMany映射?任何幫助歡迎!