Tuesday 31 December 2019

How to create a junction query, that returns a value from the junction itself?

I am trying to query a character with his stats, the problem is that the junction table holds the value of the stat. For example, the character is Fred, the stat is agility, and the value is 10. Meaning Fred has the stat of agility, and his value at it is 10. Is it possible to write a data class with @Relation and Junction to query for this?

I don't see a way to accomplish this.

data class CharacterWithStatsEntity(
    @Embedded val character: CharacterEntity,
    @Relation(
        parentColumn = "id",
        entityColumn = "id",
        entity = StatsEntity::class,
        associateBy = Junction(
            value = CharactersStatsEntity::class,
            parentColumn = "characterId",
            entityColumn = "statsId"
        )
    ) val stats: List<StatsEntity>
)

The code that I am providing is not returning the value from the junction. StatsEntity only holds the stats name, I would need a new entity StatWithValue, that would combine StatEntity and CharactersStatsEntity, and it would hold the stat name and value for the specific character.



from How to create a junction query, that returns a value from the junction itself?

No comments:

Post a Comment