fix: ignore metadata when computing relationships from payload (#8895)
This commit is contained in:
+8
@@ -16,6 +16,12 @@ describe("getSelectsAndRelationsFromObjectArray", function () {
|
|||||||
attr_null: null,
|
attr_null: null,
|
||||||
attr_undefined: undefined,
|
attr_undefined: undefined,
|
||||||
},
|
},
|
||||||
|
metadata: {
|
||||||
|
is_test: true,
|
||||||
|
nested_object: {
|
||||||
|
deeply_nested: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
attr_array: [
|
attr_array: [
|
||||||
{
|
{
|
||||||
attr_object: {
|
attr_object: {
|
||||||
@@ -43,6 +49,8 @@ describe("getSelectsAndRelationsFromObjectArray", function () {
|
|||||||
"attr_object.attr_boolean",
|
"attr_object.attr_boolean",
|
||||||
"attr_object.attr_null",
|
"attr_object.attr_null",
|
||||||
"attr_object.attr_undefined",
|
"attr_object.attr_undefined",
|
||||||
|
"metadata.is_test",
|
||||||
|
"metadata.nested_object.deeply_nested",
|
||||||
"attr_array.attr_object.attr_string",
|
"attr_array.attr_object.attr_string",
|
||||||
"attr_array.attr_object.attr_boolean",
|
"attr_array.attr_object.attr_boolean",
|
||||||
"attr_array.attr_object.attr_null",
|
"attr_array.attr_object.attr_null",
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { deduplicate } from "./deduplicate"
|
import { deduplicate } from "./deduplicate"
|
||||||
import { isObject } from "./is-object"
|
import { isObject } from "./is-object"
|
||||||
|
|
||||||
|
const KEYS_THAT_ARE_NOT_RELATIONS = ["metadata"]
|
||||||
|
|
||||||
export function getSelectsAndRelationsFromObjectArray(
|
export function getSelectsAndRelationsFromObjectArray(
|
||||||
dataArray: object[],
|
dataArray: object[],
|
||||||
options: { objectFields: string[] } = {
|
options: { objectFields: string[] } = {
|
||||||
@@ -17,23 +19,29 @@ export function getSelectsAndRelationsFromObjectArray(
|
|||||||
for (const data of dataArray) {
|
for (const data of dataArray) {
|
||||||
for (const [key, value] of Object.entries(data)) {
|
for (const [key, value] of Object.entries(data)) {
|
||||||
if (isObject(value) && !options.objectFields.includes(key)) {
|
if (isObject(value) && !options.objectFields.includes(key)) {
|
||||||
relations.push(setKey(key, prefix))
|
|
||||||
const res = getSelectsAndRelationsFromObjectArray(
|
const res = getSelectsAndRelationsFromObjectArray(
|
||||||
[value],
|
[value],
|
||||||
options,
|
options,
|
||||||
setKey(key, prefix)
|
setKey(key, prefix)
|
||||||
)
|
)
|
||||||
selects.push(...res.selects)
|
selects.push(...res.selects)
|
||||||
relations.push(...res.relations)
|
|
||||||
|
if (!KEYS_THAT_ARE_NOT_RELATIONS.includes(key)) {
|
||||||
|
relations.push(setKey(key, prefix))
|
||||||
|
relations.push(...res.relations)
|
||||||
|
}
|
||||||
} else if (Array.isArray(value)) {
|
} else if (Array.isArray(value)) {
|
||||||
relations.push(setKey(key, prefix))
|
|
||||||
const res = getSelectsAndRelationsFromObjectArray(
|
const res = getSelectsAndRelationsFromObjectArray(
|
||||||
value,
|
value,
|
||||||
options,
|
options,
|
||||||
setKey(key, prefix)
|
setKey(key, prefix)
|
||||||
)
|
)
|
||||||
selects.push(...res.selects)
|
selects.push(...res.selects)
|
||||||
relations.push(...res.relations)
|
|
||||||
|
if (!KEYS_THAT_ARE_NOT_RELATIONS.includes(key)) {
|
||||||
|
relations.push(setKey(key, prefix))
|
||||||
|
relations.push(...res.relations)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
selects.push(setKey(key, prefix))
|
selects.push(setKey(key, prefix))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user