图片上有我的桌子,我将获得这些模型,但查询时会遇到麻烦。
class PromoWithProducts {
@Embedded
lateinit var promo: Promo
@Embedded
var promoCustomer: PromoCustomer? = null
@Relation(parentColumn = "promo_id",
entityColumn = "promo_condition_promo_id",
entity = PromoCondition::class)
lateinit var promoConditions: MutableList<PromoConditionWithProducts>
}
class PromoConditionWithProducts {
@Embedded
lateinit var promoCondition: PromoCondition
@Relation(parentColumn = "promo_condition_product_id",
entityColumn = "id",
entity = Product::class)
lateinit var products: List<ProductWithStatuses>
}
我下面的promosWithConditions查询代码
@Transaction
@Query("""SELECT * FROM Promos AS promo
INNER JOIN PromoCustomers AS customer ON customer.promo_customer_promo_id = promo.promo_id
LEFT JOIN PromoConditions as condition ON promo.promo_id = condition.promo_condition_promo_id
LEFT JOIN Products as product ON product.productId = condition.promo_condition_product_id
LEFT JOIN ProductStatuses AS status ON status.product_status_product_id = product.productId
LEFT JOIN Remains AS remain ON remain.remain_product_id = product.productId AND isMain = :isMain
WHERE level = :levelId
AND customer.promo_customer_customer_id = :customerId
AND status.product_status_customer_id = :customerId
AND priceTypeId = :priceTypeId
AND contractId IN (:contractIds)
""")
abstract fun getPromosWithProducts(contractIds: List<Int?>, customerId: Int, priceTypeId: Int, levelId: Int, isMain: Boolean): Single<MutableList<PromoWithProducts>>
但是结果上Promos像promo1,promo1,promo1,promo2,promo2,promo3,promo3等重复出现
任何想法,当涉及多个联接时如何进行查询