I am facing issue with inserting data in sqlite. I am using room for this. I need to join the table to get the data. below is the json data which I need to insert data
[{
"ImgPath": "",
"ModelCode": "Model 1",
"ModelDescription": "Model 1",
"ModelID": "1",
"VarientList": [{
"MDescription": "APOLLO BLU",
"MDescriptionLong": "APOLLO BLU",
"MaterialID": "1",
"MaterialImgPath": "",
"Mcode": "APOLOL/CRSP/BLU",
"ModelColor": ""
}, {
"MDescription": "APOLLO BLK",
"MDescriptionLong": "APOLLO BLK",
"MaterialID": "2",
"MaterialImgPath": "",
"Mcode": "APOLOL/CRSP/BLK",
"ModelColor": ""
}]
}, {
"ImgPath": "",
"ModelCode": "Model 2",
"ModelDescription": "Model 2",
"ModelID": "2",
"VarientList": [{
"MDescription": "SACE BROWN",
"MDescriptionLong": "SACE BROWN",
"MaterialID": "3",
"MaterialImgPath": "",
"Mcode": "SACE/BRN",
"ModelColor": ""
}, {
"MDescription": "SACE BLU",
"MDescriptionLong": "SACE BLU",
"MaterialID": "4",
"MaterialImgPath": "",
"Mcode": "SACE/BLU",
"ModelColor": ""
}]
}]
I have taken this as reference to do this https://android.jlelse.eu/android-architecture-components-room-relationships-bf473510c14a
but I am a bit confused to insert and get the data from join table. What are the attributes will be the foreign keys and how to write the jointable for this.
//This is my Item table constructor
public ItemTable(String modelID, String modelCode, String modelDescription, String imgPath) {
this.modelID = modelID;
this.modelCode = modelCode;
this.modelDescription = modelDescription;
this.imgPath = imgPath;
}
//This is my Variant table constructor
public VariantTable(String MDescription, String MDescriptionLong, String MaterialID, String imgPath,, String Mcode,String Mcode) {
this.MDescription = MDescription;
this.MDescriptionLong = MDescriptionLong;
this.MaterialID = MaterialID;
this.Mcode = Mcode;
this.ModelColor = ModelColor;
}
I want to insert model in one table and variants of that model in second table.And I need to show the variant details as per the model. For example, If I have selected Model1 then the variants of the model1 has to come in a drop down. how to show like that, how can i do this?