Let's say that you have a Room database with two tables (entities) that are related using foreign key. (This is just a simplified example, so no need to propose a new data structure :) )
@Entity(tableName = "Streets", primaryKeys = {"Country", "City"})
public class Street {
...
}
@Entity(tableName = "Users",
primaryKeys = {"Country", "City", "Name"},
foreignKeys = @ForeignKey(entity = Street.class,
parentColumns = {"Country", "City"},
childColumns = {"Country", "City"},
onDelete = CASCADE))
public class User {
...
}
How can I retrieve all the information from the database in one query? Below works almost as expected, but I would need to add the City column as well, but how can this be done? How do you add multiple parentColumn and entityColumn?
@Query("SELECT * FROM Streets")
public abstract LiveData<List<PoJo>> getAllUsers();
public static class PoJo {
@Embedded
private Street street;
@Relation(parentColumn = "Country", entityColumn = "Country")
private List<User> mUsers;
}