Parent 与 child 属于同一类型 - 如何映射它?

Parent with a child in the same type - how to map it?

我不知道如何将 ProductEntity(ProductEntity 的一种类型)的 child 正确转换为 Product。

class ProductEntity(id: EntityID<Int>) : BaseIntEntity(id, Products) {
    companion object : BaseIntEntityClass<ProductEntity>(Products)

    var name by Products.name
    var parentProduct by ProductEntity optionalReferencedOn Products.parentProduct

    fun toPojo() = Product(idValue, name, parentProduct?.toPojo())
}

data class Product(
    val id: Int,
    val name: String,
    val parentProduct: Product?
)

此时出现错误:Type checking has 运行 into a recursive problem。 你能告诉我如何解决吗?

我找到了解决方案:

class Product(productEntity: ProductEntity) {
    val id: Int = productEntity.idValue
    val name: String = productEntity.name
    val parentProduct = productEntity.parentProduct.toPojo()
}