0
@Entity
data class User(
    @PrimaryKey
    val id: Int,
    val petsId: List<String>
)

@Entity
data class Pet(
    @PrimaryKey
    val id: Int,
    val name: String
)

How to get UserWithPets from the two User and Pet entities using Room?

data class UserWithPets(
    val id: Int,
    val pets: List<Pet>
)
  • 1
    This is just about exactly the example from the Room docs https://developer.android.com/reference/android/arch/persistence/room/Relation – zsmb13 Mar 03 '19 at 16:52
  • I was going to link https://stackoverflow.com/a/44428451/2413303 but I'm not sure how well it works with many-to-many relations. In your case, you probably want a one-to-many relation, in which case you can refer to #5 in https://medium.com/androiddevelopers/7-pro-tips-for-room-fbadea4bfbd1 – EpicPandaForce Mar 03 '19 at 16:59

0 Answers0