I am working on a picture app where I have a list of pictures entities cached in a ROOM database:
This is my Picture Entity class:
@Entity
data class PictureEntity(
@PrimaryKey
val id: String,
val title: String,
val url: String,
var isFavorite:Boolean)
I am looking to toggle the boolean value of isFavorite field when a user hits the Mark/Unmark favorite button in the UI for that particular picture item's isFavorite field
I am using this dao query but it is updating all the fields for isFavorite column.
@Update(onConflict = OnConflictStrategy.REPLACE)
suspend fun updatePicture(picture: PictureEntity)
What I want is to just update one single field for the picture which has been selected favorite.
I tried this query too but I got an error:
@Query("UPDATE picture_table SET isFavorite = NOT isFavorite")
suspend fun updatePicture()
I am totally lost and can't find any way around this issue. I will appreciate any help to get me back on track.