'Room Nested Relationship Returns Empty List

I've followed the documentation to model nested relationships in Room but despite this I cannot retrieve the data correctly. I've checked the tables using the Database Inspector and everything is filled correctly, the problem seems to lie with the modelled relationship.

Data Model:

enter image description here

Room tables:

@Entity(tableName = "journey")
data class JourneyEntity(
    @PrimaryKey(autoGenerate = false)
    val journeyId: Int,
    val name: String,
    val created: String,
    val modified: String,
    val date: String
)

@Entity(tableName = "agenda")
data class AgendaEntity(
    @PrimaryKey(autoGenerate = false)
    val agendaId: Int,
    val name: String?
)

@Entity(tableName = "stage")
data class StageEntity(
    @Embedded val excursion: ExcursionEntity,
    @PrimaryKey(autoGenerate = false)
    val stageId: Int,
    val stageType: String
)

@Entity(primaryKeys = ["agendaId", "stageId"], tableName = "agendaStageCrossRef")
data class AgendaStageCrossRef(
    val agendaId: Int,
    val stageId: Int
)

@Entity(primaryKeys = ["journeyId", "agendaId"], tableName = "journeyAgendaCrossRef")
data class JourneyAgendaCrossRef(
    val journeyId: Int,
    val agendaId: Int
)

data class AgendasWithStages(
    @Embedded val agenda: AgendaEntity,
    @Relation(
        parentColumn = "agendaId",
        entityColumn = "stageId",
        associateBy = Junction(AgendaStageCrossRef::class)
    )
    val stages: List<StageEntity>
)

data class JourneyWithAgendas(
    @Embedded val journey: JourneyEntity,
    @Relation(
        entity = AgendaEntity::class,
        parentColumn = "journeyId",
        entityColumn = "agendaId",
    )
    val agendas: List<AgendasWithStages>
)

agendas in JourneyWithAgendas is always empty after executing:

@Transaction
@Query("SELECT * FROM journey")
suspend fun getJourneys(): List<JourneyWithAgendas>


Sources

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

Source: Stack Overflow

Solution Source