'Room & Paging: How to use multimap approach?

With Room 2.4 we got the multimap feature which should according to the documentation prefered over intermediate data classes.

In my project I couldn't get this to work in combination with the paging library.

Example:

@Dao
interface DemoDao {

   @Query("""
      SELECT * FROM user U JOIN images I ON U.id = I.user_id
      WHERE U.id = :userId
      LIMIT 10
    """)
    fun getImages(userId: Long): Map<User, List<Image>>

    @Query("""
        SELECT * FROM user U JOIN images I ON U.id = I.user_id
        WHERE U.id = :userId
        LIMIT 10
    """)
    fun getPagedImages(userId: Long): PagingSource<Int, Map<User, List<Image>>> // this does not work!
}

How can I get use of the multimap feature or something similar with paging? I would like to use it because I see no other solution to limit the items in a one-to-many relation (in that case the images).

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source