objectbox / objectbox/objectbox-java

Entities in Backlink ToMany reappearing after removing

Đang mở
#1,065 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug
Ngôn ngữ chính
Java
Star
4.6k
Fork
311
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Describe the bug
When trying to remove entities from a One-To-Many relationship, they keep reappearing in the database after put() when first removing from the relationship and afterwards from box

Basic info (please complete the following information):

  • ObjectBox version: 3.1.0
  • Reproducibility: always
  • Device: Galaxy S10 (Android 11), OnePlus 6T (Android 11), Pixel 4 (Android 12)
  • OS: Android 11 and 12

To Reproduce
Steps to reproduce the behavior:

  1. Create 2 entities with a 1:N relationship (one and many)
  2. Add some entities to the ToMany (many) of the other (one).
  3. Remove 1 entity from the relationship with one.many.removeById(id)
  4. Remove the entity from the box box.remove(id)
  5. Put the parent (one) in the box again (overriding it)

Expected behavior
No matter the order, if an entity gets deleted from the box and the relation and is nowhere to be found, it should not reappear in the box.

Code
My Repo
Example code where I tested the issue in a Kotlin project

fun main(args: Array<String>) {
    val store: BoxStore = MyObjectBox.builder().name("objectbox-notes-db").build()
    val imageBox = store.boxFor<Image>().also { it.removeAll() }
    val propertyBox = store.boxFor<Property>().also { it.removeAll() }
    val originalImage = Image()
    imageBox.put(originalImage)
    originalImage.apply {
        properties.addAll(listOf(
            Property(name = "h1"),
            Property(name = "h2"),
            Property(name = "h3")
        ))
    }
    imageBox.put(originalImage)
    println("Boxed Properties: " + propertyBox.all.map { it.id })
    println("Original Image Properties: " + originalImage.properties.map { it.id })
    val removedID = propertyBox.all.first().id
    println("Removing id ${removedID}")
    val image = imageBox.get(originalImage.id).also {
        it.properties.removeById(removedID) //changing the order of these 2 will make 
        propertyBox.remove(propertyBox.all.first().id) // it work as expected
        it.properties.applyChangesToDb()
    }
    println("--------------")
    println("Both houldn't have ${removedID}: ")
    println("Boxed Properties before put: " + propertyBox.all.map { it.id })
    println("New Image Properties before put: " + image.properties.map { it.id })

    imageBox.put(image)

    println("--------------")
    println("Should still not have ${removedID}")
    println("Boxed Properties after put: " + propertyBox.all.map { it.id })
    println("New Image Properties after put: " + image.properties.map { it.id })
    }

@Entity
data class Image(
    @Id
    var id: Long = 0,
   ....
) {
    @Backlink(to = "image")
    lateinit var properties: ToMany<Property>
}

@Entity
data class Property(
    @Id
    var id: Long = 0,
   ..
) {
    lateinit var image: ToOne<Image>
}

Additional context
Flipping the order (e.g. first removing the entity from the box) and THEN removing it from the ToMany works.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với bản tái hiện bằng Kotlin và app/src/main/java/com/mobilecomputing/collit/data/datasource/LocalImageDataSource.kt, tập trung vào ToMany.removeById, applyChangesToDb và Box.put. Tái hiện cả hai thứ tự xóa và theo dõi việc cập nhật quan hệ. Được xem là hoàn tất khi Property đã xóa không xuất hiện lại sau khi put parent, bất kể thứ tự thao tác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, kotlin
Lĩnh vực
database, mobile
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.