Browse Source

fix: join query corrections

pull/6987/head
Pranav C 1 year ago
parent
commit
e1995c8f54
  1. 15
      packages/nocodb/src/db/generateLookupSelectQuery.ts

15
packages/nocodb/src/db/generateLookupSelectQuery.ts

@ -75,10 +75,10 @@ export default async function generateLookupSelectQuery({
selectQb = knex( selectQb = knex(
`${baseModelSqlv2.getTnPath(childModel.table_name)} as ${alias}`, `${baseModelSqlv2.getTnPath(childModel.table_name)} as ${alias}`,
).where( ).where(
`${alias}.${parentColumn.column_name}`, `${alias}.${childColumn.column_name}`,
knex.raw(`??`, [ knex.raw(`??`, [
`${rootAlias || baseModelSqlv2.getTnPath(parentModel.table_name)}.${ `${rootAlias || baseModelSqlv2.getTnPath(parentModel.table_name)}.${
childColumn.column_name parentColumn.column_name
}`, }`,
]), ]),
); );
@ -103,11 +103,6 @@ export default async function generateLookupSelectQuery({
const mmChildCol = await relation.getMMChildColumn(); const mmChildCol = await relation.getMMChildColumn();
const mmParentCol = await relation.getMMParentColumn(); const mmParentCol = await relation.getMMParentColumn();
// knex(
// `${baseModelSqlv2.getTnPath(
// parentModel?.table_name,
// )} as ${nestedAlias}`,
// )
selectQb selectQb
.innerJoin( .innerJoin(
baseModelSqlv2.getTnPath(mmModel.table_name, mmTableAlias), baseModelSqlv2.getTnPath(mmModel.table_name, mmTableAlias),
@ -162,10 +157,10 @@ export default async function generateLookupSelectQuery({
selectQb.join( selectQb.join(
`${baseModelSqlv2.getTnPath( `${baseModelSqlv2.getTnPath(
childModel.table_name, parentModel.table_name,
)} as ${nestedAlias}`, )} as ${nestedAlias}`,
`${nestedAlias}.${parentColumn.column_name}`, `${nestedAlias}.${parentColumn.column_name}`,
`${prevAlias}.${childColumn.column_name}`, `${prevAlias}.${parentColumn.column_name}`,
); );
} else if (relation.type === RelationTypes.MANY_TO_MANY) { } else if (relation.type === RelationTypes.MANY_TO_MANY) {
const childColumn = await relation.getChildColumn(); const childColumn = await relation.getChildColumn();
@ -226,7 +221,7 @@ export default async function generateLookupSelectQuery({
break; break;
case UITypes.LinkToAnotherRecord: case UITypes.LinkToAnotherRecord:
{ {
const nestedAlias = `__nc_sort${aliasCount++}`; const nestedAlias = getAlias();
const relation = const relation =
await lookupColumn.getColOptions<LinkToAnotherRecordColumn>(); await lookupColumn.getColOptions<LinkToAnotherRecordColumn>();
if (relation.type !== 'bt') return; if (relation.type !== 'bt') return;

Loading…
Cancel
Save