I have the following entity:
@Entity
class Foo(
@PrimaryKey
@ColumnInfo(name = "id")
val id: Long,
@ColumnInfo(name = "thing1")
val thing1: String,
@ColumnInfo(name = "thing2")
val thing2: String,
@ColumnInfo(name = "thing3")
val thing3: String,
@ColumnInfo(name = "thing4")
val thing4: String
) {
@ColumnInfo(name = "local")
var local: String? = null
}
Where local is information that is not stored on the server, only local to the phone.
Currently when I pull information from the server GSON auto fills in my values, but since "local" does not come from the server it is not populate in that object.
Is there a way that when I call update I can have Room skip the update for the "local" column without writing a custom update to insert into all other columns except "local"? The pain point is that I could have many columns and each new column I add, I would have to add that to the custom insert statement.
I have also thought of a one-to-one mapping from the server entity to a new "local" entity, however now I have to deal with the pain of a join statement everywhere I get my entity since I need the local information.
I was hoping that I could do something like this:
@Entity
class Foo(
@PrimaryKey
@ColumnInfo(name = "id")
val id: Long,
@ColumnInfo(name = "thing1")
val instructions: String,
@ColumnInfo(name = "thing2")
val instructions: String,
@ColumnInfo(name = "thing3")
val instructions: String,
@ColumnInfo(name = "thing4")
val instructions: String
) {
@Ignore
var local: String? = null
}
Using the @Ignore annotation, to try and ignore the local string on a generic update. Then provide a custom update statement to just save the local info
@Query("UPDATE foo SET local = :newLocal WHERE foo.id = :id")
fun updateLocal(id: Long, newLocal: String)
However ROOM seems to be smart enough to check that I used @Ignore on the local property and it will not compile with that update statement.
Any ideas?