objectbox / objectbox/objectbox-java
Can't save same Kotlin data class multiple times with ToMany
未关闭
还没有人认领这个 Issue。
enhancement
- 主要语言
- Java
- 星标
- 4.6k
- 派生
- 311
- PR 合并指标
- 30 天内没有已合并 PR
描述
Issue Basics
- ObjectBox version (are using the latest version?): 2.0.0
- Reproducibility: always
Reproducing the bug
Description
I'm using ObjectBox to save data. When I save the same data with ToMany, it only save the first one.
I write a test, the size of result.details is 1.
Can I save multiple same data with ToMany? How can I fix it?
Thanks for answer.
ObjectBox(version:2.0.0)
Android(target sdk version:27)
Kotlin(version:1.2.60)
Code
@Test
fun orderDetailTest() {
val orderBox: Box<Order> = store.boxFor()
// 儲存兩個內容相同的資料
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)
}
Entities
@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>
}
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用所示的 Order 和 OrderDetail 实体复现 orderDetailTest 用例,然后检查 ToMany 反向链接和 ToOne 关系是如何持久化的。当保存两个相同的 OrderDetail 实例后得到 result.details.size == 2,或记录预期的限制时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- android, kotlin
- 领域
- database, mobile
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100