copyToRealm adds object with empty id

Why this code adds a Restaurant document with empty id? I have the @PrimaryKey on _id field.

            realm.write {
                val restaurant = Restaurant().apply {
                    this.userID="6360f373a6f3933e4c9cf6f3"
                    this.name = "name"
                    this.adresa = "location"
                    this.telefon = "07500000".toLong()
                }
                copyToRealm(restaurant)
            }

Issue solvedddddddddddd

Hello @Ciprian_Gabor,

Glad to know your issue got resolved. Could you please discuss a brief on your solution, to help our mobile community :smiley:

Many Thanks in advance.

Cheers, :performing_arts:
Henna

Sure!

_id field should be:

@PrimaryKey
var _id: ObjectId = ObjectId.create()