mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Check if item exists instead of relying on presence of pk
This commit is contained in:
@@ -301,11 +301,10 @@ export class PayloadService {
|
||||
const relatedRecord: Partial<Item> = payload[relation.many_field];
|
||||
const hasPrimaryKey = relatedRecord.hasOwnProperty(relation.one_primary);
|
||||
|
||||
let relatedPrimaryKey: PrimaryKey;
|
||||
|
||||
if (hasPrimaryKey) {
|
||||
relatedPrimaryKey = relatedRecord[relation.one_primary];
|
||||
let relatedPrimaryKey: PrimaryKey = relatedRecord[relation.one_primary];
|
||||
const exists = hasPrimaryKey && !!(await itemsService.readByKey(relatedPrimaryKey));
|
||||
|
||||
if (exists) {
|
||||
if (relatedRecord.hasOwnProperty('$delete') && relatedRecord.$delete) {
|
||||
await itemsService.delete(relatedPrimaryKey);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user