Objectbox: How to initialize ToMany<> relation in kotlin
See original GitHub issueHere is my class:
@Entity
class EmailMessage () {
@Id var id: Long = 0
var subject: String = ""
var body: String = ""
lateinit attachments: ToMany<Attachment>
}
Usually ‘attachments’ property has some data before inserting into DB. but accessing ‘attachments’ before ‘put’ wouldn’t have initialized the property and i don’t think its a good idea to ‘put’ into DB first just for initialization which is an extra unwanted step i would like to avoid.
In short, my requirement is to have some data in ‘attachments’ before inserting into DB. Do we have a better way to do it ?, Am i missing something here?
Note: Assigning null also doesn’t work
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Objectbox: How to initialize ToMany<> relation in kotlin
@Entity data class EmailMessage ( @Id var id: Long = 0, var subject: String = "", var body: String = "", var attachments:...
Read more >Relations - ObjectBox Docs
ObjectBox Relations : Learn how to create and update to-one and to-many ... Relations are lazily initialized: the actual target objects are fetched...
Read more >Kotlin Support - ObjectBox Docs
When defining relations in Kotlin, keep in mind that relation properties must be var . Otherwise they can not be initialized as described...
Read more >Troubleshooting - ObjectBox Docs
Solutions for common issues with ObjectBox db for Java, Kotlin and Android. ... DB's last relation ID is higher than from model ......
Read more >ObjectBox Java
Java's String[] and Kotlin's Array<String> are now a supported database type. ... Backlinks for to-many relations: now ObjectBox is "relation complete" with ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have the same problem, while i use retrofit, the ToOne<> field cannot been assigned by gson, i must do it manually
Closing as @BukT0p reported this (relations in Android + Kotlin + local unit tests) fixed. Please comment on and re-open #220 if local unit tests in Android+Kotlin still make problems. -ut