Browse Source

fix: handle if lookup column is LTAR

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5767/head
Pranav C 1 year ago
parent
commit
1d7027f67a
  1. 77
      packages/nocodb/src/services/public-metas.service.ts

77
packages/nocodb/src/services/public-metas.service.ts

@ -63,22 +63,7 @@ export class PublicMetasService {
// load related table metas // load related table metas
for (const col of view.model.columns) { for (const col of view.model.columns) {
if (UITypes.LinkToAnotherRecord === col.uidt) { await this.extractRelatedMetas({ col, relatedMetas });
const colOpt = await col.getColOptions<LinkToAnotherRecordType>();
relatedMetas[colOpt.fk_related_model_id] = await Model.getWithInfo({
id: colOpt.fk_related_model_id,
});
if (colOpt.type === 'mm') {
relatedMetas[colOpt.fk_mm_model_id] = await Model.getWithInfo({
id: colOpt.fk_mm_model_id,
});
}
} else if (UITypes.Lookup === col.uidt) {
await this.extractLookupRelatedMetas({
lookupColOption: await col.getColOptions<LookupColumn>(),
relatedMetas,
});
}
} }
view.relatedMetas = relatedMetas; view.relatedMetas = relatedMetas;
@ -86,6 +71,43 @@ export class PublicMetasService {
return view; return view;
} }
private async extractRelatedMetas({
col,
relatedMetas = {},
}: {
col: Column<any>;
relatedMetas: Record<string, Model>;
}) {
if (UITypes.LinkToAnotherRecord === col.uidt) {
await this.extractLTARRelatedMetas({
ltarColOption: await col.getColOptions<LinkToAnotherRecordColumn>(),
relatedMetas,
});
} else if (UITypes.Lookup === col.uidt) {
await this.extractLookupRelatedMetas({
lookupColOption: await col.getColOptions<LookupColumn>(),
relatedMetas,
});
}
}
private async extractLTARRelatedMetas({
ltarColOption,
relatedMetas = {},
}: {
ltarColOption: LinkToAnotherRecordColumn;
relatedMetas: { [key: string]: Model };
}) {
relatedMetas[ltarColOption.fk_related_model_id] = await Model.getWithInfo({
id: ltarColOption.fk_related_model_id,
});
if (ltarColOption.type === 'mm') {
relatedMetas[ltarColOption.fk_mm_model_id] = await Model.getWithInfo({
id: ltarColOption.fk_mm_model_id,
});
}
}
private async extractLookupRelatedMetas({ private async extractLookupRelatedMetas({
lookupColOption, lookupColOption,
relatedMetas = {}, relatedMetas = {},
@ -96,7 +118,7 @@ export class PublicMetasService {
const relationCol = await Column.get({ const relationCol = await Column.get({
colId: lookupColOption.fk_relation_column_id, colId: lookupColOption.fk_relation_column_id,
}); });
const lookupCol = await Column.get({ const lookedUpCol = await Column.get({
colId: lookupColOption.fk_lookup_column_id, colId: lookupColOption.fk_lookup_column_id,
}); });
@ -104,24 +126,23 @@ export class PublicMetasService {
// if not already extracted // if not already extracted
if (!relatedMetas[relationCol.fk_model_id]) { if (!relatedMetas[relationCol.fk_model_id]) {
relatedMetas[relationCol.fk_model_id] = await Model.getWithInfo({ relatedMetas[relationCol.fk_model_id] = await Model.getWithInfo({
id: lookupCol.fk_model_id, id: relationCol.fk_model_id,
}); });
} }
// extract meta for table in which looked up column belongs // extract meta for table in which looked up column belongs
// if not already extracted // if not already extracted
if (!relatedMetas[lookupCol.fk_model_id]) { if (!relatedMetas[lookedUpCol.fk_model_id]) {
relatedMetas[lookupCol.fk_model_id] = await Model.getWithInfo({ relatedMetas[lookedUpCol.fk_model_id] = await Model.getWithInfo({
id: lookupCol.fk_model_id, id: lookedUpCol.fk_model_id,
}); });
} }
// if looked up column is a lookup column do the same for it by recursion // extract metas related to the looked up column
if (lookupCol.uidt === UITypes.Lookup) { await this.extractRelatedMetas({
await this.extractLookupRelatedMetas({ col: lookedUpCol,
lookupColOption: await lookupCol.getColOptions<LookupColumn>(), relatedMetas,
relatedMetas, });
});
}
} }
async publicSharedBaseGet(param: { sharedBaseUuid: string }): Promise<any> { async publicSharedBaseGet(param: { sharedBaseUuid: string }): Promise<any> {

Loading…
Cancel
Save