Browse Source

fix: handle if lookup column is LTAR

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

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

@ -63,16 +63,26 @@ export class PublicMetasService {
// load related table metas
for (const col of view.model.columns) {
await this.extractRelatedMetas({ col, relatedMetas });
}
view.relatedMetas = relatedMetas;
return view;
}
private async extractRelatedMetas({
col,
relatedMetas = {},
}: {
col: Column<any>;
relatedMetas: Record<string, Model>;
}) {
if (UITypes.LinkToAnotherRecord === col.uidt) {
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,
await this.extractLTARRelatedMetas({
ltarColOption: await col.getColOptions<LinkToAnotherRecordColumn>(),
relatedMetas,
});
}
} else if (UITypes.Lookup === col.uidt) {
await this.extractLookupRelatedMetas({
lookupColOption: await col.getColOptions<LookupColumn>(),
@ -81,9 +91,21 @@ export class PublicMetasService {
}
}
view.relatedMetas = relatedMetas;
return view;
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({
@ -96,7 +118,7 @@ export class PublicMetasService {
const relationCol = await Column.get({
colId: lookupColOption.fk_relation_column_id,
});
const lookupCol = await Column.get({
const lookedUpCol = await Column.get({
colId: lookupColOption.fk_lookup_column_id,
});
@ -104,25 +126,24 @@ export class PublicMetasService {
// if not already extracted
if (!relatedMetas[relationCol.fk_model_id]) {
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
// if not already extracted
if (!relatedMetas[lookupCol.fk_model_id]) {
relatedMetas[lookupCol.fk_model_id] = await Model.getWithInfo({
id: lookupCol.fk_model_id,
if (!relatedMetas[lookedUpCol.fk_model_id]) {
relatedMetas[lookedUpCol.fk_model_id] = await Model.getWithInfo({
id: lookedUpCol.fk_model_id,
});
}
// if looked up column is a lookup column do the same for it by recursion
if (lookupCol.uidt === UITypes.Lookup) {
await this.extractLookupRelatedMetas({
lookupColOption: await lookupCol.getColOptions<LookupColumn>(),
// extract metas related to the looked up column
await this.extractRelatedMetas({
col: lookedUpCol,
relatedMetas,
});
}
}
async publicSharedBaseGet(param: { sharedBaseUuid: string }): Promise<any> {
const project = await Project.getByUuid(param.sharedBaseUuid);

Loading…
Cancel
Save