There are such Entity (Store and Check):
Shops
@Entity(indices = {@Index(value = {"inn"}, unique = true)}) public class Shops { @PrimaryKey(autoGenerate = true) public int id; public String name; public String inn; } Receipts
@Entity(foreignKeys = @ForeignKey( entity = Shops.class, parentColumns = "id", childColumns = "shop_id") ) public class Receipts { @PrimaryKey(autoGenerate = true) public int id; public Long date; public double totalSum; public int shop_id; } You need to get a list of Receipts , in which shop_id will be replaced by Shops.name . Those. perform table joins.
Of
Receive
On pure SQLite, the query would be:
SELECT Receipts.id, Receipts.date, Receipts.totalSum, Shops.name FROM Receipts INNER JOIN Shops ON Shops.id = Receipts.shop_id; Those. Dao view:
@Query("SELECT Receipts.id, Receipts.date, Receipts.totalSum, Shops.name " + "FROM Receipts " + "INNER JOIN Shops ON Shops.id = Receipts.shop_id;") public List<Receipts> getReceiptsWithShops(); However, List<Receipts> not suitable as a return data type.
What is the best way to act when implementing through Room? Create a new Receipts class?


ReceiptWithShop. Relation Documentation - eugeneek