我想隱式轉換一個案例類到另一個案例類,但不能讓代碼工作。我的編輯給了我Seq [LegacyPhase]不會轉換爲期望的Seq [Phase]的錯誤。任何人都可以指出我的方向嗎?提前致謝!隱式轉換的案例類問題
implicit def legacyToDashboardBrand(brand: LegacyDashboardBrand)(implicit session: Session): DashboardBrand = {
val phaseSeq: Seq[Phase] = (for { phaseDataset <- dashboardPhasesQ if phaseDataset.brandId === brand.id
} yield phaseDataset).list.toSeq
DashboardBrand(id = brand.id, projectId = brand.projectId, name = brand.name, currentPhase = brand.currentPhase, phases = phaseSeq)
}
implicit def legacyToDashboardPhase(phase: LegacyPhase): Phase = {
Phase(id = phase.id, brandId = phase.brandId, title = phase.title, steps = Seq())
}
編輯:如果我在第一個隱式轉換定義中執行第二個隱式轉換行,它將起作用。
implicit def legacyToDashboardBrand(brand: LegacyDashboardBrand)(implicit session: Session): DashboardBrand = {
val legacyPhaseSeq = (for {
phaseDataset <- dashboardPhasesQ if phaseDataset.brandId === brand.id
} yield phaseDataset).list.toSeq
val phaseSeq: Seq[Phase] = legacyPhaseSeq.map(phase =>
Phase(id = phase.id, brandId = phase.brandId, title = phase.title, steps = Seq())
)
DashboardBrand(id = brand.id, projectId = brand.projectId, name = brand.name, currentPhase = brand.currentPhase, phases = phaseSeq)
}
你能告訴我們確切的錯誤嗎?什麼是'dashboardPhasesQ'? –
嘿,彼得。 dashboardPhasesQ是一個表查詢。 val dashboardPhasesQ = TableQuery [LegacyPhaseTable] –