Skip to content

Build your personal knowledge base with Trilium Notes

allow duplicated attribute per note (in effect attributes can be multi-valued). Closes #33

azivner7c74c77a2c52
diff --git a/db/migrations/0072__allow_multiple_attributes_per_note.sql b/db/migrations/0072__allow_multiple_attributes_per_note.sql
new file mode 100644
index 0000000000..9023a6ab1a
--- /dev/null
+++ b/db/migrations/0072__allow_multiple_attributes_per_note.sql
@@ -0,0 +1 @@
+DROP INDEX IDX_attributes_noteId_name;
\ No newline at end of file
diff --git a/db/schema.sql b/db/schema.sql
index 13df0a2622..1d9f7a3fc7 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -118,4 +118,3 @@ CREATE INDEX IDX_note_images_noteId ON note_images (noteId);
CREATE INDEX IDX_note_images_imageId ON note_images (imageId);
CREATE INDEX IDX_note_images_noteId_imageId ON note_images (noteId, imageId);
CREATE INDEX IDX_attributes_noteId ON attributes (noteId);
-CREATE UNIQUE INDEX IDX_attributes_noteId_name ON attributes (noteId, name);
diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js
index 8b6318c10d..9043bb60c2 100644
--- a/src/public/javascripts/dialogs/attributes.js
+++ b/src/public/javascripts/dialogs/attributes.js
@@ -28,7 +28,7 @@ const attributesDialog = (function() {
function isValid() {
for (let attrs = self.attributes(), i = 0; i < attrs.length; i++) {
- if (self.isEmptyName(i) || self.isNotUnique(i)) {
+ if (self.isEmptyName(i)) {
return false;
}
}
diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js
index 9789bc431b..bb69c817ba 100644
--- a/src/routes/api/notes.js
+++ b/src/routes/api/notes.js
@@ -62,6 +62,8 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
const {query, params} = getSearchQuery(attrFilters, searchText);
+ console.log(query, params);
+
const noteIds = await sql.getColumn(query, params);
res.send(noteIds);
@@ -152,7 +154,7 @@ function getSearchQuery(attrFilters, searchText) {
searchParams.push(searchText); // two occurences in searchCondition
}
- const query = `SELECT notes.noteId FROM notes
+ const query = `SELECT DISTINCT notes.noteId FROM notes
${joins.join('\r\n')}
WHERE
notes.isDeleted = 0
diff --git a/src/services/app_info.js b/src/services/app_info.js
index ad29652a21..509dcace9f 100644
--- a/src/services/app_info.js
+++ b/src/services/app_info.js
@@ -3,7 +3,7 @@
const build = require('./build');
const packageJson = require('../../package');
-const APP_DB_VERSION = 71;
+const APP_DB_VERSION = 72;
module.exports = {
app_version: packageJson.version,
diff --git a/src/views/index.ejs b/src/views/index.ejs
index d6446ab73c..88f2fde8bc 100644
--- a/src/views/index.ejs
+++ b/src/views/index.ejs
@@ -394,8 +394,7 @@
<td>
<!-- Change to valueUpdate: blur is necessary because jQuery UI autocomplete hijacks change event -->
<input type="text" class="attribute-name" data-bind="value: name, valueUpdate: 'blur', event: { blur: $parent.attributeChanged }"/>
-
- <div style="color: red" data-bind="if: $parent.isNotUnique($index())">Attribute name must be unique per note.</div>
+ <div style="color: yellowgreen" data-bind="if: $parent.isNotUnique($index())"><span class="glyphicon glyphicon-info-sign"></span> Duplicate attribute.</div>
<div style="color: red" data-bind="if: $parent.isEmptyName($index())">Attribute name can't be empty.</div>
</td>
<td>