diff --git a/packages/server/src/api/controllers/row/utils/sqlUtils.ts b/packages/server/src/api/controllers/row/utils/sqlUtils.ts index e66a0b5bf6..1793d64b89 100644 --- a/packages/server/src/api/controllers/row/utils/sqlUtils.ts +++ b/packages/server/src/api/controllers/row/utils/sqlUtils.ts @@ -200,8 +200,8 @@ export async function buildSqlFieldList( if ( isView && - source.schema?.[field.name] && - !helpers.views.isVisible(source.schema[field.name]) && + (!source.schema?.[field.name] || + !helpers.views.isVisible(source.schema[field.name])) && !containsFormula ) { continue diff --git a/packages/server/src/api/controllers/row/utils/tests/sqlUtils.spec.ts b/packages/server/src/api/controllers/row/utils/tests/sqlUtils.spec.ts index 12a5edd30b..365f571fcf 100644 --- a/packages/server/src/api/controllers/row/utils/tests/sqlUtils.spec.ts +++ b/packages/server/src/api/controllers/row/utils/tests/sqlUtils.spec.ts @@ -362,33 +362,6 @@ describe("buildSqlFieldList", () => { expect(result).toEqual(["table.amount"]) }) - it("includes relationships fields when flagged", async () => { - const otherTable = new TableConfig("linkedTable") - .withField("id", FieldType.NUMBER) - .withPrimary("id") - .withDisplay("name") - .create() - - const table = new TableConfig("table") - .withRelation("link", otherTable._id) - .withField("formula", FieldType.FORMULA) - .create() - - const view = new ViewConfig(table) - .withVisible("name") - .withHidden("amount") - .create() - - const result = await buildSqlFieldList(view, allTables, { - relationships: true, - }) - expect(result).toEqual([ - "table.name", - "linkedTable.id", - "linkedTable.name", - ]) - }) - it("includes relationships columns", async () => { const otherTable = new TableConfig("linkedTable") .withField("id", FieldType.NUMBER) @@ -420,6 +393,29 @@ describe("buildSqlFieldList", () => { ]) }) + it("excludes relationships fields when view is not included in the view", async () => { + const otherTable = new TableConfig("linkedTable") + .withField("id", FieldType.NUMBER) + .withPrimary("id") + .withDisplay("name") + .create() + + const table = new TableConfig("table") + .withRelation("link", otherTable._id) + .withField("formula", FieldType.FORMULA) + .create() + + const view = new ViewConfig(table) + .withVisible("name") + .withHidden("amount") + .create() + + const result = await buildSqlFieldList(view, allTables, { + relationships: true, + }) + expect(result).toEqual(["table.name"]) + }) + it("does not include relationships columns for hidden links", async () => { const otherTable = new TableConfig("linkedTable") .withField("id", FieldType.NUMBER)