According to https://developer.android.com/training/data-storage/room/relationships
We can have one-to-many relationships
public class UserWithPlaylists {
@Embedded public User user;
@Relation(
parentColumn = "userId",
entityColumn = "userCreatorId"
)
public List<Playlist> playlists;
}
@Transaction
@Query("SELECT * FROM User")
public List<UserWithPlaylists> getUsersWithPlaylists();
In both entity User and Playlist, we have added a column named sort_key
The purpose is, when we perform query, we can do the following
@Transaction
@Query("SELECT * FROM User order by sort_key")
public List<UserWithPlaylists> getUsersWithPlaylists();
We can control the order of List<UserWithPlaylists>.
But, how about List<Playlist> playlists child entity?
How can we define a custom query for child entity Playlist, so that we can have control over List<Playlist> playlists ordering?