Closed
Description
Issue Basics
- ObjectBox version (are using the latest version?): 2.3.2
- Reproducibility: always
Reproducing the bug
Description
When you have an entity that defines a ToOne
relation to another entity, you can use isNull
to check if the other entity is null. However, this does not work properly if the other entity does not exist in the database anymore.
For instance, you have an entity A that defines a ToOne
relation to entity B. If you delete B, entity A will still retain the ID and so isNull
will incorrectly return false. But when accessing entity B with target
, the result will be null.
Entities
@Entity
data class A(
@Id
var dbId: Long = 0,
) {
lateinit var content: ToOne<B>
}
@Entity
data class B(
@Id
var dbId: Long = 0,
)
Misc
Apologies if this is expected behaviour, but it seems counter intuitive to me. The workaround is simple, just check if target
is null.
Metadata
Metadata
Assignees
Labels
No labels