I could use a little help. I have created all the tables, and I can create a relationship to retrieve the application, but I do not know how I can retrieve the list of vehicle brands with the models.
@Entity(tableName = "application_table", indices = [Index(value = ["name"], unique = true)])
data class ApplicationItem(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id") val id: Int? = 0,
@ColumnInfo(name = "name") val name: String
)
data class ApplicationWithBrandAndModel(
@Embedded val application: ApplicationItem,
@Relation(
entity = BrandOfVehicleItem::class,
parentColumn = "userId",
entityColumn = "brandId"
)
val brands: List<BrandWithModel>
)
data class BrandWithModel(
@Embedded val brand: BrandOfVehicleItem,
@Relation(
parentColumn = "path",
entityColumn = "brandCreatorId"
)
val models: List<ModelOfVehicleItem>
)

In short you need to utilise the AppBrandCrossRef table to reference (associate) the ApplicationItem with the Brand to get the list of BrandWithModel's.
The keyword here, that Room uses is associateBy, so in the
@Relationyou need to specify the association using theassociateByargument.The
associateByargument itself takes aJunctionargument which is where you define the cross reference table and the respective columns.So I believe that you want:-
The following is a working example.
So the entities used to demonstrate are :-
Model
Brand
ApplicationItem
ApplicationBrandCrossRef
BrandWithModel is
ApplicationWithBrandAndModel is
Dao's in AllDao are :-
The following was utilised to test:-
The Result output to the log :-