Skip to content
Snippets Groups Projects
Commit 1401d71ccb75 authored by Frank Bessou's avatar Frank Bessou :spider_web:
Browse files

fix: erase relations when an empty array is provided

parent 463c9223b7c3
No related branches found
No related tags found
No related merge requests found
......@@ -181,9 +181,6 @@
const restrictionsUpdate: string[] = [`X is ${resource}, X eid ${id}`];
let counter = 0;
Object.entries(data).forEach(([key, value]) => {
if (Array.isArray(value) && value.length === 0) {
return;
}
if (key in schema.entities[resource]) {
attributeUpdates.push(`X ${key} ${JSON.stringify(value)}`);
} else if (subjectRelationsNames(resource).includes(key)) {
......@@ -191,7 +188,9 @@
throw new Error(`An array is expected for relation ${key}.`);
}
relationUpdates.push(`X ${key} Y${counter}`);
restrictionsUpdate.push(`Y${counter} eid IN (${value.join(", ")})`);
if (value.length > 0) {
restrictionsUpdate.push(`Y${counter} eid IN (${value.join(", ")})`);
}
counter += 1;
} else if (
key.startsWith("reverse_") &&
......@@ -200,8 +199,10 @@
if (!Array.isArray(value)) {
throw new Error(`An array is expected for relation ${key}.`);
}
relationUpdates.push(`Y${counter} ${key} X`);
restrictionsUpdate.push(`Y${counter} eid ${value.join(", ")}`);
relationUpdates.push(`Y${counter} ${key.replace("reverse_", "")} X`);
if (value.length > 0) {
restrictionsUpdate.push(`Y${counter} eid IN (${value.join(", ")})`);
}
counter += 1;
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment