Apologies is this is a dumb question. I'm trying to get familiar with Kotlin and came across an issue. I have a kotlin app where I store data using Room.
This is my entity class:
@Entity
data class Link(@PrimaryKey(autoGenerate = true) var _id: Int,
@ColumnInfo(name = "link_url") var linkUrl: String?,
@ColumnInfo(name = "timestamp") var timestamp: Long?)
How can I create a new instance of Link
without specifying the _id
?
ie
var link: Link = Link("url", 12334)
Thank you in advance!
You can create another constructor with @Ignore
annotation, so that it will be ignored by Room:
@Ignore
constructor(var linkUrl: String?, timestamp: Long?) : this (null, linkUrl, timestamp)
If you pass null
for the autogenerated field, it will generate new value automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With