Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realm does not support properties of this type (not Date related) #1684

Closed
darrinps opened this issue Mar 9, 2024 · 3 comments
Closed

Realm does not support properties of this type (not Date related) #1684

darrinps opened this issue Mar 9, 2024 · 3 comments

Comments

@darrinps
Copy link

darrinps commented Mar 9, 2024

How frequently does the bug occur?

Always

Description

I have a KMP app that is getting a "Realm does not support properties of this type" when I try to execute it.

Here is the code:

class Patient() : RealmObject {
    @PrimaryKey
    var _id: ObjectId = ObjectId()
    var firstName: String = ""
    var lastName: String = ""
    var visits: Array<PelletInsertionVisit> = arrayOf(PelletInsertionVisit())  <---- ERROR on this line

    constructor(first: String = "", last: String = "") : this() {
        firstName = first
        lastName = last
    }
}

class PelletInsertionVisit() : RealmObject {
    @PrimaryKey
    var _id: ObjectId = ObjectId()
    var visitDate = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) //Note this is a Long, not a Date
    var pelletsUsed: Array<Pellet> = arrayOf(Pellet())


    constructor(pelletArray: Array<Pellet>, date: Long) : this() {
        visitDate = date
        pelletsUsed = pelletArray
    }
}

class Pellet(): RealmObject {
    @PrimaryKey
    var _id: ObjectId = ObjectId()
    var size = PelletSize.ZERO.value
    var lotNumber: String = "UNKNOWN"


    constructor(pelletSize: Int, lot: String = "") : this() {
        size = pelletSize
        lotNumber = lot
    }
}

enum class PelletSize (val value: Int){
    ZERO(0),  //UNSET
    TEN(10),
    TWENTY_FIVE(25),
    FIFTY(50),
    ONE_HUNDRED(100),
    TWO_HUNDRED(200);

    companion object {
        private val types = entries.associateBy { it.value }

        fun findByValue(value: Int): PelletSize? = types[value]
    }
}

I thought as long as the variables within the class were supported, it was OK to create arrays of class objects. What am I doing wrong here, please?

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

1.11.0

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Kotlin 1.9.22 Android 34

Build environment

Android Studio version: 2023.2.1
Android Build Tools version: 35-rc1
Gradle version: 8.4

Copy link

sync-by-unito bot commented Mar 9, 2024

➤ PM Bot commented:

Jira ticket: RKOTLIN-1032

@nirinchev
Copy link
Member

According to the docs, collections in Kotlin are represented using RealmList rather than an array. Can you try replacing the array declaration with:

var visits: RealmList<PelletInsertionVisit> = realmListOf()

@darrinps
Copy link
Author

BINGO! Thanks for solving and apologies for not seeing this in the documentation.

Closing.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants