我有以下课程:
case class Product( title : String, description: String, contract: Contract)
case class Contract(contractType: ContractType, price: Int )
case class ContractType(description: String)
和这些 DTO:
case class ProductDto(id: Long, title: String, description: String, contractType: ContractTypeDto, price: Int)
case class ContractTypeDto(id: Long, description: String)
我需要创建一个方法来返回产品列表,但数据填充在 DTO 中,如下所示:
def list = Db.query[Product].fetch().toList.map(x => ProductDto(x.id, x.title,
x.description, ContractTypeDto(x.contract.contractType.id,
x.contract.contractType.description), x.contract.price))
问题是我无法访问 x.contract.contractType.id 但 SORM 允许我访问x.id
(在第一级),有什么办法吗?
谢谢