'How can I resolve TypeError: Cannot read property 'findAll' of undefined (Sequelize)?
In my project I am using PostgreSql as database. I have tables in PgAdmin, I am developing API's by calling tables in PgAdmin using Sequelize ORM
All API has GET request. Below is the index.js file where I write simple SQL to get the data.
index.js
class Person_Table extends Model {
conn;
rec;
constructor(conn, schema, rec) {
super(conn, schema, "Person_Table", {
code: character(2, true),
date: date(true),
className: character(1, true),
.....// many more columns
}, true);
this.rec = rec;
}
async getData(date) {
try {
const data = await this._conn.query(`
(SELECT ${this._schema}."Person_Table"."code", ${this._schema}."Person_Table"."date", ${this._schema}."Person_Table"."className",${this._schema}."Person_Table"."ui" FROM ${this._schema}."Person_Table" WHERE "date" = '${date}')`);
return data[0];
})
} catch (error) {
throw error;
}
}
}
Problem is there are multiple columns in table. So I don’t want return rows straight from the DB as is, in a long, flat object structure. Instead, reorganize each row in a nested object model, so the structure is apparent to the client. Something like below:
return (await this._model.findAll()).map(term => {
code: term.code,
trans: {
code: term.transCode,
date: term.date
},
// and so on....
I am getting TypeError: Cannot read property 'findAll' of undefined (Sequelize) error. I am not sure why. I need help to reorganize each row in a nested object model
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
