Browse Source

fix: ignore row ordering and fix nested mm lookup bug

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

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

@ -184,10 +184,15 @@ export default async function generateLookupSelectQuery({
selectQb selectQb
.innerJoin( .innerJoin(
baseModelSqlv2.getTnPath(mmModel.table_name, mmTableAlias), baseModelSqlv2.getTnPath(mmModel.table_name, mmTableAlias),
knex.ref(`${mmTableAlias}.${mmParentCol.column_name}`), knex.ref(`${mmTableAlias}.${mmChildCol.column_name}`),
'=', '=',
knex.ref(`${nestedAlias}.${parentColumn.column_name}`), knex.ref(`${prevAlias}.${childColumn.column_name}`),
) )
.innerJoin(knex.raw('?? as ??', [baseModelSqlv2.getTnPath(parentModel.table_name), nestedAlias]),
knex.ref(`${mmTableAlias}.${mmParentCol.column_name}`),
'=',
knex.ref(`${nestedAlias}.${parentColumn.column_name}`),
)
.where( .where(
knex.ref(`${mmTableAlias}.${mmChildCol.column_name}`), knex.ref(`${mmTableAlias}.${mmChildCol.column_name}`),
'=', '=',
@ -276,7 +281,7 @@ export default async function generateLookupSelectQuery({
const subQueryAlias = getAlias(); const subQueryAlias = getAlias();
if (baseModelSqlv2.isPg) { if (baseModelSqlv2.isPg) {
selectQb.orderBy(`${lookupColumn.title}`, 'asc'); // selectQb.orderBy(`${lookupColumn.title}`, 'asc');
// // alternate approach with array_agg // // alternate approach with array_agg
// return { // return {
// builder: knex // builder: knex
@ -316,7 +321,7 @@ export default async function generateLookupSelectQuery({
}; };
} else if (baseModelSqlv2.isSqlite) { } else if (baseModelSqlv2.isSqlite) {
// ref: https://stackoverflow.com/questions/13382856/sqlite3-join-group-concat-using-distinct-with-custom-separator // ref: https://stackoverflow.com/questions/13382856/sqlite3-join-group-concat-using-distinct-with-custom-separator
selectQb.orderBy(`${lookupColumn.title}`, 'asc'); // selectQb.orderBy(`${lookupColumn.title}`, 'asc');
return { return {
builder: knex builder: knex
.select( .select(

Loading…
Cancel
Save