Browse Source

fix: Handling table with no primary key

re #436

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/441/head
Pranav C 3 years ago
parent
commit
28db164fd2
  1. 11
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

11
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

@ -1206,7 +1206,12 @@ class BaseModelSql extends BaseModel {
* @param {String} [args.sort] - comma separated column names where each column name is cn ascending and -cn is cn descending * @param {String} [args.sort] - comma separated column names where each column name is cn ascending and -cn is cn descending
* @returns {Promise<Object[]>} return child rows * @returns {Promise<Object[]>} return child rows
*/ */
async hasManyChildren({child, parentId, conditionGraph = null, ...args}: XcFilterWithAlias & { child: string, parentId: any }) { async hasManyChildren({
child,
parentId,
conditionGraph = null,
...args
}: XcFilterWithAlias & { child: string, parentId: any }) {
try { try {
const {where, limit, offset, sort, ...restArgs} = this._getListArgs(args); const {where, limit, offset, sort, ...restArgs} = this._getListArgs(args);
let {fields} = restArgs; let {fields} = restArgs;
@ -1296,7 +1301,7 @@ class BaseModelSql extends BaseModel {
let fields = fields1 || f || '*'; let fields = fields1 || f || '*';
try { try {
if (fields !== '*' && fields.split(',').indexOf(this.pks[0].cn) === -1) { if (fields !== '*' && this.pks[0] && fields.split(',').indexOf(this.pks?.[0]?.cn) === -1) {
fields += ',' + this.pks[0].cn; fields += ',' + this.pks[0].cn;
} }
@ -1349,7 +1354,7 @@ class BaseModelSql extends BaseModel {
try { try {
// todo: use fields in readbyPk // todo: use fields in readbyPk
if (fields !== '*' && fields.split(',').indexOf(this.pks[0].cn) === -1) { if (fields !== '*' && this.pks[0] && fields.split(',').indexOf(this.pks[0].cn) === -1) {
fields += ',' + this.pks[0].cn; fields += ',' + this.pks[0].cn;
} }

Loading…
Cancel
Save