question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Objectbox: How to initialize ToMany<> relation in kotlin

See original GitHub issue

Here 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
crazyxucommented, Nov 17, 2017

I have the same problem, while i use retrofit, the ToOne<> field cannot been assigned by gson, i must do it manually

0reactions
greenrobot-teamcommented, Apr 16, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found