2012-02-18 7 views
0

UPDATE:私の現在の状況を反映するために、サンプルを変更リフトマッパー - OneToManyマッピングとトレイト

かなり持ち上げて新しいと私は自分のアプリケーションのためのモデルを作成しようとしています。私はDRYの精神に物事を残したいので、私は、私のモデルのフィールドのいくつかを指定するために、特性ミックスインを使いたいと思っています。私は従業員の内の1つのマッピングに多くのcontactInfosを持って見ることができるように

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] 

:例えば、私は私が私のEmployeeクラスにミックスインPerson形質を持っています。これが動作しているようですが、私は私のPerson特性に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] 

:ように見えます。しかし、私はこれを達成する方法を理解することはできません... OneToManyの特性を継承することは可能ですか?助けを歓迎します!

答えて

1

少し試してみたら、PersonのOneToManyマッピングを行う特性をPersonContactInfoに分けることで、これを機能させることができました。

それでも
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] 

ない、これはこの問題を解決するための方法ですが、ITYは仕事をしていませんかどうかわから:)

:これは、今

trait Person[T <: Person[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) 
} 

trait PersonToPersonContacts[P <: Person[P], PCI <: PersonContactInfo[PCI, P]] extends OneToMany[Long,P] { 
    self: P => 
    def contactInfoMeta:LongKeyedMetaMapper[PCI] with PCI 
    object contactInfos extends MappedOneToMany(contactInfoMeta, contactInfoMeta.person) 
} 

class Employee extends IdPK with Person[Employee] with PersonToPersonContacts[Employee, EmployeeContactInfo] { 
    def getSingleton = Employee 
    override def contactInfoMeta = EmployeeContactInfo 
} 
object Employee extends Employee with LongKeyedMetaMapper[Employee] 

を見て、私のPersonContactInfoが今どのように見えるかです

関連する問題