Hi guys, I’m trying to fetch data from multiple tables.
The first table data contains a country_id column which I use to fetch the country name from the other table.
I have linked them together using a chain of promises but every time I run the app, I get the following error:
_{"_zone_symbol__currentTask":{“type”:“microTask”,“state”:“notScheduled”,“source”:“Promise.then”,“zone”:“angular”,“cancelFn”:“nullCount”:0}}
Below is my code snippet:
N.B: database is a SQLiteObject
transactionPartners() {
let partners = [];
let rawPartners;
let transactionPartners = [];
let rows;
return this.database.executeSql("SELECT * FROM corp_fin_tran_partners", {})
.then((data1) => {
rawPartners = data1;
rows = data1.rows;
for(let i = 0; i < rows.length; i++) {
partners.push({
id: rows.item(i).id,
company_id: rows.item(i).company_id,
name: rows.item(i).name,
email: rows.item(i).email,
tel: rows.item(i).tel,
comp_numb: rows.item(i).comp_numb,
tin: rows.item(i).tin,
address: rows.item(i).address,
country_id: rows.item(i).country_id,
state_id: rows.item(i).state_id,
document: rows.item(i).document
})
}
return this.getCountry(partners);
})
.then((data2) => {
for (let i = 0; i < rows.length; i++) {
transactionPartners.push({
id: rows.item(i).id,
company_id: rows.item(i).company_id,
name: rows.item(i).name,
email: rows.item(i).email,
tel: rows.item(i).tel,
comp_numb: rows.item(i).comp_numb,
tin: rows.item(i).tin,
address: rows.item(i).address,
country_id: rows.item(i).country_id,
state_id: rows.item(i).state_id,
document: rows.item(i).document,
country: data2.rows.item(i).name
})
}
return transactionPartners;
})
.catch((error) => {
alert("transactionPartners(): " + JSON.stringify(error))
})
}
getCountry(partners) {
let countries = null;
// let partners = this.mergePartners;
partners.forEach( partner => {
this.database.executeSql("SELECT name FROM countries WHERE id=(?)", [partner.country_id])
.then((data) => {
countries += data;
alert(countries.rows.item(0).name);
})
})
return countries;
}