На картинке мои таблицы, и я собираюсь получить эти модели, но у меня будут проблемы с запросом.
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 ... и т. Д.
любые идеи, как сделать запрос, когда есть отношение ко многим и нескольким объединениям