Random Dev Notes (Room ~@Relation~ Dao Error)
Wednesday, May 27, 2020
Apparently with Room on Android, you can’t use @Insert Dao methods with a POJO. It throws an unhelpful error that took two entire days to figure out. I’m writing this so I never forget and to maybe help someone out who googles it next.
Say you have a model and POJO like:
@Entity(...) data class User( val id: String, val name: String ) @Entity(...) data class Pet( val id: String, val type: String, val name: String, val userId: String ) data class UserWithPets( val id: String, val name: String, @Relation( parentColumn = "id", entityColumn = "userId" ) val pets: List<Pet> ) If you write a Dao method like:…more