Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
it's now possible to mark relation as inheritable (previously this was hardcoded for specific relation names)
azivner2eb1a9705fc2
diff --git a/db/migrations/0107__add_inheritable_attribute_to_relations.sql b/db/migrations/0107__add_inheritable_attribute_to_relations.sqlnew file mode 100644index 0000000000..282c13f122--- /dev/null+++ b/db/migrations/0107__add_inheritable_attribute_to_relations.sql@@ -0,0 +1 @@+ALTER TABLE relations ADD isInheritable int DEFAULT 0 NULL;\ No newline at end of filediff --git a/db/schema.sql b/db/schema.sqlindex b6a3a17f46..5335c76161 100644--- a/db/schema.sql+++ b/db/schema.sql@@ -140,6 +140,7 @@ CREATE TABLE relationssourceNoteId TEXT not null,name TEXT not null,targetNoteId TEXT not null,+ isInheritable int DEFAULT 0 NULL,position INT default 0 not null,dateCreated TEXT not null,dateModified TEXT not null,diff --git a/src/entities/relation.js b/src/entities/relation.jsindex 25c2760e81..1c98fcd606 100644--- a/src/entities/relation.js+++ b/src/entities/relation.js@@ -8,7 +8,7 @@ const sql = require('../services/sql');class Relation extends Entity {static get tableName() { return "relations"; }static get primaryKeyName() { return "relationId"; }- static get hashedProperties() { return ["relationId", "sourceNoteId", "name", "targetNoteId", "dateModified", "dateCreated"]; }+ static get hashedProperties() { return ["relationId", "sourceNoteId", "name", "targetNoteId", "isInheritable", "dateModified", "dateCreated"]; }async getSourceNote() {return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.sourceNoteId]);@@ -25,6 +25,10 @@ class Relation extends Entity {this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM relations WHERE sourceNoteId = ?`, [this.sourceNoteId]);}+ if (!this.isInheritable) {+ this.isInheritable = false;+ }+if (!this.isDeleted) {this.isDeleted = false;}diff --git a/src/public/javascripts/dialogs/relations.js b/src/public/javascripts/dialogs/relations.jsindex 7b2aeeddb2..62dc212c02 100644--- a/src/public/javascripts/dialogs/relations.js+++ b/src/public/javascripts/dialogs/relations.js@@ -123,6 +123,7 @@ function RelationsModel() {relationId: '',name: '',targetNoteId: '',+ isInheritable: 0,isDeleted: 0,position: 0}));@@ -176,7 +177,7 @@ async function showDialog() {$dialog.dialog({modal: true,- width: 800,+ width: 900,height: 500});}diff --git a/src/routes/api/relations.js b/src/routes/api/relations.jsindex d6c3e11851..d88362fecb 100644--- a/src/routes/api/relations.js+++ b/src/routes/api/relations.js@@ -33,6 +33,7 @@ async function updateNoteRelations(req) {relationEntity.name = relation.name;relationEntity.targetNoteId = relation.targetNoteId;+ relationEntity.isInheritable = relation.isInheritable;relationEntity.position = relation.position;relationEntity.isDeleted = relation.isDeleted;diff --git a/src/services/app_info.js b/src/services/app_info.jsindex 10b6c9bf97..40b2f7a8e9 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 = 106;+const APP_DB_VERSION = 107;const SYNC_VERSION = 1;module.exports = {diff --git a/src/services/relations.js b/src/services/relations.jsindex 6f259e8052..5c273871f2 100644--- a/src/services/relations.js+++ b/src/services/relations.js@@ -46,7 +46,8 @@ async function getEffectiveRelations(noteId) {JOIN notes ON notes.noteId = branches.parentNoteIdWHERE notes.isDeleted = 0 AND branches.isDeleted = 0)- SELECT relations.* FROM relations JOIN tree ON relations.sourceNoteId = tree.noteId WHERE relations.isDeleted = 0 AND relations.name IN ('runOnNoteView')`, [noteId]);+ SELECT relations.* FROM relations JOIN tree ON relations.sourceNoteId = tree.noteId+ WHERE relations.isDeleted = 0 AND (relations.isInheritable = 1 OR relations.sourceNoteId = ?)`, [noteId, noteId]);}module.exports = {diff --git a/src/services/sync_update.js b/src/services/sync_update.jsindex d342849f06..6fad891abe 100644--- a/src/services/sync_update.js+++ b/src/services/sync_update.js@@ -40,7 +40,7 @@ async function updateEntity(sync, entity, sourceId) {await updateApiToken(entity, sourceId);}else {- throw new Error(`Unrecognized entity type ${sync}`);+ throw new Error(`Unrecognized entity type ${entityName}`);}}diff --git a/src/views/index.ejs b/src/views/index.ejsindex 740790de34..d7a6f68984 100644--- a/src/views/index.ejs+++ b/src/views/index.ejs@@ -612,6 +612,7 @@<th>ID</th><th>Relation name</th><th>Target note</th>+ <th>Inheritable</th><th></th></tr></thead>@@ -639,6 +640,9 @@<span class="input-group-addon relations-show-recent-notes" title="Show recent notes" style="background: url('/images/icons/clock-16.png') no-repeat center; cursor: pointer;"></span></div></td>+ <td title="Inheritable relations are automatically inherited to the child notes">+ <input type="checkbox" value="1" data-bind="checked: isInheritable" />+ </td><td title="Delete" style="padding: 13px; cursor: pointer;"><span class="glyphicon glyphicon-trash" data-bind="click: $parent.deleteRelation"></span></td>