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
attributes can be inherited through special relation "inheritAttributes"
azivnerddbd4f73c840
diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xmlindex e820877ad4..1317d871f8 100644--- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml+++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml@@ -1,6 +1,6 @@<?xml version="1.0" encoding="UTF-8"?><dataSource name="document.db">- <database-model serializer="dbm" rdbms="SQLITE" format-version="4.9">+ <database-model serializer="dbm" rdbms="SQLITE" format-version="4.11"><root id="1"><ServerVersion>3.16.1</ServerVersion></root>@@ -59,7 +59,6 @@<index id="25" parent="6" name="sqlite_autoindex_api_tokens_1"><NameSurrogate>1</NameSurrogate><ColNames>apiTokenId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="26" parent="6">@@ -128,7 +127,6 @@<index id="38" parent="7" name="sqlite_autoindex_attributes_1"><NameSurrogate>1</NameSurrogate><ColNames>attributeId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="39" parent="7">@@ -190,21 +188,17 @@<index id="50" parent="8" name="sqlite_autoindex_branches_1"><NameSurrogate>1</NameSurrogate><ColNames>branchId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><index id="51" parent="8" name="IDX_branches_noteId_parentNoteId"><ColNames>noteIdparentNoteId</ColNames>- <ColumnCollations></ColumnCollations></index><index id="52" parent="8" name="IDX_branches_noteId"><ColNames>noteId</ColNames>- <ColumnCollations></ColumnCollations></index><index id="53" parent="8" name="IDX_branches_parentNoteId"><ColNames>parentNoteId</ColNames>- <ColumnCollations></ColumnCollations></index><key id="54" parent="8"><ColNames>branchId</ColNames>@@ -232,7 +226,6 @@ parentNoteId</ColNames><index id="59" parent="9" name="sqlite_autoindex_event_log_1"><NameSurrogate>1</NameSurrogate><ColNames>eventId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="60" parent="9">@@ -289,7 +282,6 @@ parentNoteId</ColNames><index id="70" parent="10" name="sqlite_autoindex_images_1"><NameSurrogate>1</NameSurrogate><ColNames>imageId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="71" parent="10">@@ -337,21 +329,17 @@ parentNoteId</ColNames><index id="79" parent="11" name="sqlite_autoindex_note_images_1"><NameSurrogate>1</NameSurrogate><ColNames>noteImageId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><index id="80" parent="11" name="IDX_note_images_noteId_imageId"><ColNames>noteIdimageId</ColNames>- <ColumnCollations></ColumnCollations></index><index id="81" parent="11" name="IDX_note_images_noteId"><ColNames>noteId</ColNames>- <ColumnCollations></ColumnCollations></index><index id="82" parent="11" name="IDX_note_images_imageId"><ColNames>imageId</ColNames>- <ColumnCollations></ColumnCollations></index><key id="83" parent="11"><ColNames>noteImageId</ColNames>@@ -413,20 +401,16 @@ imageId</ColNames><index id="94" parent="12" name="sqlite_autoindex_note_revisions_1"><NameSurrogate>1</NameSurrogate><ColNames>noteRevisionId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><index id="95" parent="12" name="IDX_note_revisions_noteId"><ColNames>noteId</ColNames>- <ColumnCollations></ColumnCollations></index><index id="96" parent="12" name="IDX_note_revisions_dateModifiedFrom"><ColNames>dateModifiedFrom</ColNames>- <ColumnCollations></ColumnCollations></index><index id="97" parent="12" name="IDX_note_revisions_dateModifiedTo"><ColNames>dateModifiedTo</ColNames>- <ColumnCollations></ColumnCollations></index><key id="98" parent="12"><ColNames>noteRevisionId</ColNames>@@ -493,12 +477,10 @@ imageId</ColNames><index id="109" parent="13" name="sqlite_autoindex_notes_1"><NameSurrogate>1</NameSurrogate><ColNames>noteId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><index id="110" parent="13" name="IDX_notes_type"><ColNames>type</ColNames>- <ColumnCollations></ColumnCollations></index><key id="111" parent="13"><ColNames>noteId</ColNames>@@ -539,7 +521,6 @@ imageId</ColNames><index id="118" parent="14" name="sqlite_autoindex_options_1"><NameSurrogate>1</NameSurrogate><ColNames>name</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="119" parent="14">@@ -575,7 +556,6 @@ imageId</ColNames><index id="125" parent="15" name="sqlite_autoindex_recent_notes_1"><NameSurrogate>1</NameSurrogate><ColNames>branchId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="126" parent="15">@@ -596,7 +576,6 @@ imageId</ColNames><index id="129" parent="16" name="sqlite_autoindex_source_ids_1"><NameSurrogate>1</NameSurrogate><ColNames>sourceId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><key id="130" parent="16">@@ -659,12 +638,10 @@ imageId</ColNames><index id="143" parent="19" name="IDX_sync_entityName_entityId"><ColNames>entityNameentityId</ColNames>- <ColumnCollations></ColumnCollations><Unique>1</Unique></index><index id="144" parent="19" name="IDX_sync_syncDate"><ColNames>syncDate</ColNames>- <ColumnCollations></ColumnCollations></index><key id="145" parent="19"><ColNames>id</ColNames>diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xmlnew file mode 100644index 0000000000..c0e01cabc7--- /dev/null+++ b/.idea/sqldialects.xml@@ -0,0 +1,6 @@+<?xml version="1.0" encoding="UTF-8"?>+<project version="4">+ <component name="SqlDialectMappings">+ <file url="PROJECT" dialect="SQLite" />+ </component>+</project>\ No newline at end of filediff --git a/src/entities/note.js b/src/entities/note.jsindex d37ff3cc81..89c05e6b8a 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -72,17 +72,28 @@ class Note extends Entity {async getAttributes() {const attributes = await repository.getEntities(`- WITH RECURSIVE tree(noteId, level) AS (- SELECT ?, 0- UNION- SELECT branches.parentNoteId, tree.level + 1 FROM branches- JOIN tree ON branches.noteId = tree.noteId- JOIN notes ON notes.noteId = branches.parentNoteId- WHERE notes.isDeleted = 0 AND branches.isDeleted = 0- )- SELECT attributes.* FROM attributes JOIN tree ON attributes.noteId = tree.noteId- WHERE attributes.isDeleted = 0 AND (attributes.isInheritable = 1 OR attributes.noteId = ?)- ORDER BY level, noteId, position`, [this.noteId, this.noteId]);+ WITH RECURSIVE+ tree(noteId, level) AS (+ SELECT ?, 0+ UNION+ SELECT branches.parentNoteId, tree.level + 1 FROM branches+ JOIN tree ON branches.noteId = tree.noteId+ JOIN notes ON notes.noteId = branches.parentNoteId+ WHERE notes.isDeleted = 0+ AND branches.isDeleted = 0+ ),+ treeWithAttrs(noteId, level) AS (+ SELECT * FROM tree+ UNION+ SELECT attributes.value, treeWithAttrs.level + 1 FROM attributes+ JOIN treeWithAttrs ON treeWithAttrs.noteId = attributes.noteId+ WHERE attributes.isDeleted = 0+ AND attributes.type = 'relation'+ AND attributes.name = 'inheritAttributes'+ )+ SELECT attributes.* FROM attributes JOIN treeWithAttrs ON attributes.noteId = treeWithAttrs.noteId+ WHERE attributes.isDeleted = 0 AND (attributes.isInheritable = 1 OR attributes.noteId = ?)+ ORDER BY level, noteId, position`, [this.noteId, this.noteId]);// attributes are ordered so that "closest" attributes are first// we order by noteId so that attributes from same note stay together. Actual noteId ordering doesn't matter.diff --git a/src/services/attributes.js b/src/services/attributes.jsindex 6cfea1c867..176678f112 100644--- a/src/services/attributes.js+++ b/src/services/attributes.js@@ -20,7 +20,8 @@ const BUILTIN_ATTRIBUTES = [// relation names{ type: 'relation', name: 'runOnNoteView' },{ type: 'relation', name: 'runOnNoteTitleChange' },- { type: 'relation', name: 'runOnAttributeChange' }+ { type: 'relation', name: 'runOnAttributeChange' },+ { type: 'relation', name: 'inheritAttributes' }];async function getNotesWithLabel(name, value) {