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映射?任何帮助欢迎!