Skip to content

Commit

Permalink
fix(adminPanel): Fix UsedBy queries for data elements and data-tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Port committed Apr 12, 2024
1 parent 54d4c16 commit 6f059bd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/database/src/TupaiaDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,11 @@ function getColSelector(connection, inputColStr) {

const params = inputColStr.split(jsonOperatorPattern);
const allButFirst = params.slice(1);
const lastIndexOfLookupAsText = inputColStr.lastIndexOf('->>');
const lastIndexOfLookupAsJson = inputColStr.lastIndexOf('->');
const selector = lastIndexOfLookupAsText >= lastIndexOfLookupAsJson ? '#>>' : '#>';

// Turn `config->item->>colour` into `config #>> '{item,colour}'`
// For some reason, Knex fails when we try to convert it to `config->'item'->>'colour'`
return connection.raw(`?? #>> '{${allButFirst.map(() => '??').join(',')}}'`, params);
return connection.raw(`?? ${selector} '{${allButFirst.map(() => '??').join(',')}}'`, params);
}

0 comments on commit 6f059bd

Please sign in to comment.