I am fetching data from room tables using this data class.
data class TrainSchStat
(
@Embedded val train: TrnTable = TrnTable(),
@Relation(
entity = StatTable::class,
parentColumn = "srCode",
entityColumn = "code",
)
val fromStation: StatTable = StatTable(),
@Relation(
entity = StatTable::class,
parentColumn = "destCode",
entityColumn = "code",
)
val toStation: StatTable = StatTable(),
@Relation(
entity = SchTable::class,
parentColumn = "num",
entityColumn = "numb"
)
val schedules: List<SchWithStats> = emptyList()
)
data class SchWithStats(
@Embedded val schedule: SchTable = SchTable(),
@Relation(
entity = StatTable::class,
parentColumn = "stnCode",
entityColumn = "code",
)
val station: StatTable = StatTable()
)
Tables are
station table
@Entity("RoomStations",
indices = [
Index(value = ["code"])
])
data class StatTable(
@PrimaryKey
val code:String="",//station code
val name:String="",//station name
val lat:Double=0.0,//station lat
val lng:Double=0.0,//station lng
val type:Int=0,//station type
val stateName:String="",//station state
val stateCode:String="",//state code
)
Train Table
@Entity("RoomTrains",
indices = [
Index(value = ["num"])
])
data class TrnTable(
@PrimaryKey
val num:Int=0,//train number
val name:String="",//train name
val type:Int=0,//train type
val srCode:String="",//source station code
val srcName:String="",//source station name
val destCode:String="",//destination station code
val destName:String="",//destination station name
val runDays:Int=0,//train rundays
val classes:String="",//train classes
val totalDist:Float=0.0f,//total distance
val jourTime:Int=0,//journey time
val depArr:String="",//
val updatedOn:Int=0
)
Schedule table
@Entity(
tableName = "RoomSchedule",
primaryKeys = ["numb", "stnCode"],
indices = [
Index(value = ["numb"])
]
)
data class SchTable(
val numb:Int=0,//train number
val stnCode:String="",//station code
val statno:Int=0,//station no
val haltno:Int=0,//halt number
val stop:Int=0,//is stop
val sta:Int=0,//station sta
val std:Int=0,//station std
val dayNum:Int=0,//daynum
val km: Float=0.0f,//kilometer
)
This data class is fetching all the data from table.
I want to get only only station name from RoomStations table corresponding to station code from RoomSchedule table.
And Only stations where stop is 1 from Schedule table
How can I do that?