@Entity data class Dog( @PrimaryKey val dogId: Long, val dogOwnerId: Long, val name: String, val cuteness: Int, val barkVolume: Int, val breed: String )
@Entity data class Owner(@PrimaryKey val ownerId: Long, val name: String)
data class DogAndOwner( val owner: Owner, val dog: Dog )
SELECT * FROM Owner
SELECT * FROM Dog WHERE dogOwnerId IN (ownerId1, ownerId2, …)
data class DogAndOwner( @Embedded val owner: Owner, @Relation( parentColumn = "ownerId", entityColumn = "dogOwnerId" ) val dog: Dog )
@Transaction @Query("SELECT * FROM Owner") fun getDogsAndOwners(): List<DogAndOwner>
data class OwnerWithDogs( val owner: Owner, val dogs: List<Dog> )
data class OwnerWithDogs( @Embedded val owner: Owner, @Relation( parentColumn = "ownerId", entityColumn = "dogOwnerId" ) val dogs: List<Dog> )
@Transaction @Query("SELECT * FROM Owner") fun getDogsAndOwners(): List<OwnerWithDogs>
@Entity(primaryKeys = ["dogId", "ownerId"]) data class DogOwnerCrossRef( val dogId: Long, val ownerId: Long )
SELECT Dog.dogId AS dogId, Dog.dogOwnerId AS dogOwnerId, Dog.name AS name, _junction.ownerId FROM DogOwnerCrossRef AS _junction INNER JOIN Dog ON (_junction.dogId = Dog.dogId) WHERE _junction.ownerId IN (ownerId1, ownerId2, …)
data class OwnerWithDogs( @Embedded val owner: Owner, @Relation( parentColumn = "ownerId", entityColumn = "dogId", associateBy = Junction(DogOwnerCrossRef::class) ) val dogs: List<Dog> )
@Transaction @Query("SELECT * FROM Owner") fun getOwnersWithDogs(): List<OwnerWithDogs>
data class Pup( val name: String, val cuteness: Int = 11 )
data class OwnerWithPups( @Embedded val owner: Owner, @Relation( parentColumn = "ownerId", entity = Dog::class, entityColumn = "dogOwnerId" ) val dogs: List<Pup> )
data class OwnerWithDogs( @Embedded val owner: Owner, @Relation( parentColumn = "ownerId", entity = Dog::class, entityColumn = "dogOwnerId", projection = ["name"] ) val dogNames: List<String> )