From 8e1f8c869b21c8f1dce7b5bdc73e244ea2eac128 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 3 Dec 2019 20:31:34 +0100 Subject: [PATCH] new @parentCount virtual search attribute, closes #738 --- src/services/build_search_query.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/build_search_query.js b/src/services/build_search_query.js index 2f54afb76..0bac8b428 100644 --- a/src/services/build_search_query.js +++ b/src/services/build_search_query.js @@ -11,7 +11,8 @@ const VIRTUAL_ATTRIBUTES = [ "content", "type", "mime", - "text" + "text", + "parentCount" ]; module.exports = function(filters, selectedColumns = 'notes.*') { @@ -43,6 +44,11 @@ module.exports = function(filters, selectedColumns = 'notes.*') { accessor = `${alias}.${property}`; } + else if (property === 'parentCount') { + // need to cast as string for the equality operator to work + // for >= etc. it is cast again to DECIMAL + accessor = `CAST((SELECT COUNT(1) FROM branches WHERE branches.noteId = notes.noteId AND isDeleted = 0) AS STRING)`; + } else { accessor = "notes." + property; }