diff --git a/lib/model/query/entities.js b/lib/model/query/entities.js index 0238ea98f..568af77dc 100644 --- a/lib/model/query/entities.js +++ b/lib/model/query/entities.js @@ -592,7 +592,12 @@ const _get = (includeSource) => { `} ${!includeSource ? sql`` : sql` LEFT JOIN entity_def_sources ON entity_defs."sourceId" = entity_def_sources."id" - LEFT JOIN submission_defs ON submission_defs.id = entity_def_sources."submissionDefId" + LEFT JOIN ( + SELECT submission_defs.* FROM submission_defs + JOIN submissions ON submission_defs."submissionId" = submissions.id + JOIN forms ON submissions."formId" = forms.id + WHERE submissions."deletedAt" IS NULL AND forms."deletedAt" IS NULL + ) as submission_defs on submission_defs.id = entity_def_sources."submissionDefId" LEFT JOIN ( SELECT submissions.*, submission_defs."userAgent" FROM submissions JOIN submission_defs ON submissions.id = submission_defs."submissionId" AND root