diff --git a/packages/core/database/src/__tests__/view/view-inference.test.ts b/packages/core/database/src/__tests__/view/view-inference.test.ts index 8294bfba4..33b56de94 100644 --- a/packages/core/database/src/__tests__/view/view-inference.test.ts +++ b/packages/core/database/src/__tests__/view/view-inference.test.ts @@ -34,7 +34,7 @@ describe('view inference', function () { await db.sync(); - const viewName = 'user_posts'; + const viewName = 'test_view'; const dropViewSQL = `DROP VIEW IF EXISTS ${viewName}`; await db.sequelize.query(dropViewSQL); diff --git a/packages/core/database/src/query-interface/postgres-query-interface.ts b/packages/core/database/src/query-interface/postgres-query-interface.ts index 5e973dc38..183c4465c 100644 --- a/packages/core/database/src/query-interface/postgres-query-interface.ts +++ b/packages/core/database/src/query-interface/postgres-query-interface.ts @@ -153,10 +153,14 @@ export default class PostgresQueryInterface extends QueryInterface { // handle column alias const from = ast[0].from; - const findAs = from.find((from) => from.as === columnExprTable); + if (columnExprTable === null && column.expr.type === 'column_ref') { + columnExprTable = from[0].table; + } else { + const findAs = from.find((from) => from.as === columnExprTable); - if (findAs) { - columnExprTable = findAs.table; + if (findAs) { + columnExprTable = findAs.table; + } } return columnUsage.column_name === column.expr.column && columnUsage.table_name === columnExprTable;