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; }