Reputation: 13
I have the following structure to save to app database:
@Entity
public class Project{
@primaryKey
String id;
String name;
[...]
Country country;
[...]
}
And my Country Entity looks like the following:
@Entity
public class Country {
@PrimaryKey
private String id;
private String name;
private String pk;
}
Now to my Question: How do I make Room know the Relation between Country and Project Entity?
Upvotes: 1
Views: 824
Reputation: 103451
Please refer the official documentation
https://developer.android.com/reference/android/arch/persistence/room/Relation.html
Upvotes: 1
Reputation: 661
Room can not have nested entities, you can embedd POJO classes in an entity but it will get flattened into a single table or if you want Country as an entity then you'll have to store county_id in Project entity and index it as foreign key.
More on Embedded fields: https://developer.android.com/reference/android/arch/persistence/room/Embedded.html
More on Foreign key: https://developer.android.com/reference/android/arch/persistence/room/ForeignKey.html
Upvotes: 1