From 853b8583a1976de5d1b7457b47807c904284139f Mon Sep 17 00:00:00 2001 From: Guillaume Gautreau Date: Tue, 3 Nov 2020 10:32:27 +0100 Subject: [PATCH] fix: request the right fields for belongsTo relationships with casing difference between DB and JS Linked to CU-9wq6rf --- src/services/query-builder.js | 2 +- test/services/query-builder.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/query-builder.js b/src/services/query-builder.js index 8ef89a01..8ba42fac 100644 --- a/src/services/query-builder.js +++ b/src/services/query-builder.js @@ -33,7 +33,7 @@ function QueryBuilder(model, opts, params) { .filter((association) => ['HasOne', 'BelongsTo'].includes(association.associationType)) .forEach((association) => { const targetFields = Object.values(association.target.tableAttributes) - .map((attribute) => attribute.field); + .map((attribute) => attribute.fieldName); const explicitAttributes = (fieldNamesRequested || []) .filter((name) => name.startsWith(`${association.as}.`)) diff --git a/test/services/query-builder.test.js b/test/services/query-builder.test.js index 0295b646..57da157d 100644 --- a/test/services/query-builder.test.js +++ b/test/services/query-builder.test.js @@ -32,8 +32,8 @@ describe('services > query-builder', () => { function setup() { const target = { tableAttributes: { - id: { field: 'uid' }, - name: { field: 'name' }, + id: { field: 'Uid', fieldName: 'uid' }, + name: { field: 'Name', fieldName: 'name' }, }, unscoped: () => ({ name: 'user' }), };