I'm using ObjectBox to save data. When I save the same data with ToMany, it only save the first one.
- ObjectBox(version:2.0.0)
- Android(target sdk version:27)
- Kotlin(version:1.2.60)
Here is my code.
@Entity
data class Order(@Id var id: Long = 0,
val createTime: Long = 0,
val total: Int = 0) {
@Backlink(to = "order")
lateinit var details: ToMany<OrderDetail>
}
@Entity
data class OrderDetail(@Id var id: Long = 0,
val productName: String = "",
val productSpecName: String = "",
val productSpecPrice: Int = 0,
val quantity: Int = 0,
val subtotal: Int = 0) {
lateinit var order: ToOne<Order>
}
The test
@Test
fun orderDetailTest() {
val orderBox = store.boxFor(Order::class.java)
// 儲存兩個內容相同的資料
val order = Order().apply {
this.details.add(OrderDetail(productSpecName = "ABC"))
this.details.add(OrderDetail(productSpecName = "ABC"))
}
val orderId = orderBox.put(order)
val result = orderBox.get(orderId)
assert(result.details.size == 2)
}
The size of result.details is 1.
Can I save multiple same data with ToMany? How can I fix it?
Thanks for answer.