I’m trying to setup a notification service in Android Mobile using the Room API.
How do I automatically delete all notification records associated with a template_id_fk
where template_id_fk
can be of any 3 data classes (Income, Expense or Bill)?.
Here is the @Entity
I’m trying to build for my Notification model, since Room doesn’t support Polymorphic Association out of the box, how do I setup my database to allow for this?
@Entity(
tableName="notification",
foreignKeys = [
ForeignKey(
entity = Income::class,
parentColumns = arrayOf("uid"),
childColumns = arrayOf("template_id_fk"),
onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.CASCADE
),
ForeignKey(
entity = Expense::class,
parentColumns = arrayOf("uid"),
childColumns = arrayOf("template_id_fk"),
onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.CASCADE
),
ForeignKey(
entity = Bill::class,
parentColumns = arrayOf("uid"),
childColumns = arrayOf("template_id_fk"),
onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.CASCADE
)
]
)
data class Notification (
@PrimaryKey
val uid: String = "${UUID.randomUUID()}",
@ColumnInfo(name= "event_key")val eventKey: NotificationEventKey,
@ColumnInfo(name= "transaction_id") val transactionId: TransactionId?,
@ColumnInfo(name= "template_id_fk") val templateId: TemplateId,
@ColumnInfo(name= "is_read")val isRead: Boolean = false,
@ColumnInfo(name= "created") val created : ISODateTime,
@ColumnInfo(name= "updated") val updated : ISODateTime,
)