Insert into multiple tables using the space save library

This is the first time I use Room. I have a class:

@Entity(tableName = "users")
class User{
   @PrimaryKey
   @ColumnInfo(name = "id")
   @SerializedName("id")
   String id;

   @ColumnInfo(name = "name")
   @SerializedName("name")
   String name;

   @SerializedName("shift")
   @Ignore
   List<Shift> shifts; 
}

@Entity(tableName = "shifts")
class Shift{
   @PrimaryKey
   @ColumnInfo(name = "id")
   @SerializedName("id")
   String id;

   @ColumnInfo(name = "start_time")
   @SerializedName("start_time")
   String startTime;

   @ColumnInfo(name = "end_time")
   @SerializedName("end_time")
   String endTime;
}

I want these two to be separate tables in the database, so I cannot annotate @Embedded user, as he will create a single table using all fields as columns. I use the above User class to store the json response from the server, where I get information about the user and the change of data in the json object.

Shift shifts, users? , @Embeded, shift , .

- , ? .

+4
1

- Shift , users?

DAO @Transaction, User Shift.

.

Shift, @ForeignKey User , User Shift. User Shift .

+2

Source: https://habr.com/ru/post/1687604/


All Articles