Reputation: 2806
@Entity(tableName = "gym_address_table")
data class GymAddress(@PrimaryKey val id: String, val country: Country, val unitNumber: String)
@Entity(tableName = "country_table")
data class Country(
@PrimaryKey
val id: String,
val isoCode: String,
val dialCode: String,
val name: String,
val flagPhoto: String
)
So, when I try to compile this I got this error:
Cannot figure out how to save this field into database. You can consider adding a type converter for it.
private final com.gymapp.main.data.model.country.Country country = null;```
I am new to Room implementation so I am not sure how to solve this.
Upvotes: 0
Views: 1197
Reputation: 497
Clearly the error is that Country is null, the object is null therefore it won't save as such. The main problem is that you are not passing the values, so you may need a class to pass the values with a method called Save that saves country (the object) in the database
Upvotes: 0
Reputation: 715
Country is a relationship to GymAddress. You need to decide which type of relationship it has, Can a GymAddress have multiple Country.class? Potentially not so if a one-to-one relationship, you would need to annotate it accordingly with
@Embedded
Room is great, the Relationship requires additional data classes to save and retrieve etc. Which can become a pain.
Check out Android Room Relationships to understand it further
Upvotes: 2