Код: Выделить всё
@Entity(
tableName = "user",
primaryKeys = ["id"],
)
data class User(
@ColumnInfo(name = "id")
val userId: Long,
// Other columns here
)
@Entity(
tableName = "entry",
primaryKeys = ["id"],
foreignKeys = [
ForeignKey(
entity = User::class,
parentColumns = ["id"],
childColumns = ["user_id"],
onDelete = ForeignKey.CASCADE,
),
],
)
data class Entry(
@ColumnInfo(name = "id")
val id: Long,
@ColumnInfo(name = "user_id")
val userId: Long,
@ColumnInfo(name = "active")
val active: Boolean,
)
Код: Выделить всё
@Query("SELECT * FROM entry WHERE id = :id")
suspend fun getEntry(id: Long): Entry?
@Update
suspend fun updateEntry(entry: Entry)
Код: Выделить всё
suspend fun setActive(entryId: Long) {
val entry = dao.getEntry(entryId)
entry?.let {
dao.updateEntry(entry.copy(active = true))
}
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... ting-a-row