new @parentCount virtual search attribute, closes #738

This commit is contained in:
zadam 2019-12-03 20:31:34 +01:00
parent 0e2f8b5734
commit 8e1f8c869b

View File

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