axe-api 1.5.0-rc-7 → 1.5.0-rc-9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -197,8 +197,13 @@ const getRelatedData = (version, data, withArray, model, modelList, database, ha
|
|
|
197
197
|
}
|
|
198
198
|
const dataFieldKey = getPrimaryOrForeignKeyByRelation(definedRelation, dataField);
|
|
199
199
|
const searchFieldKey = getPrimaryOrForeignKeyByRelation(definedRelation, searchField);
|
|
200
|
-
// We should find the parent Primary Key values.
|
|
201
|
-
|
|
200
|
+
// We should find the parent Primary Key values. We shouldn't allow NULL or
|
|
201
|
+
// undefined as the primary key value. NULL or undefined cannot be used as a
|
|
202
|
+
// key between relations. Also, there is no need to have duplicated values
|
|
203
|
+
// in the array.
|
|
204
|
+
const parentPrimaryKeyValues = [
|
|
205
|
+
...new Set(data.map((item) => item[dataFieldKey]).filter((item) => item)),
|
|
206
|
+
];
|
|
202
207
|
// Selecting the special field for the relations
|
|
203
208
|
let selectColumns = ["*"];
|
|
204
209
|
if (clientQuery.fields.length > 0) {
|
|
@@ -236,7 +241,12 @@ const getRelatedData = (version, data, withArray, model, modelList, database, ha
|
|
|
236
241
|
foreignModelQuery.whereNull(foreignModel.instance.deletedAtColumn);
|
|
237
242
|
}
|
|
238
243
|
// Fetching related records by foreignKey and primary key values.
|
|
239
|
-
let relatedRecords =
|
|
244
|
+
let relatedRecords = [];
|
|
245
|
+
// If there is not any parentPrimaryKeyValues, that means the relationship
|
|
246
|
+
// query would return empty. So no need to execute those query at this phase.
|
|
247
|
+
if (parentPrimaryKeyValues.length > 0) {
|
|
248
|
+
relatedRecords = yield foreignModelQuery.whereIn(searchFieldKey, parentPrimaryKeyValues);
|
|
249
|
+
}
|
|
240
250
|
// Adding related data source to the request tags to set cache tag values
|
|
241
251
|
const { primaryKey } = foreignModel.instance;
|
|
242
252
|
const cacheConfig = foreignModel.getCacheConfiguration(handler);
|