Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

🛠️ Fix: update value with full path when creating new note in relation field #1093

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/cellTypes/Editor/RelationEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
) => {
switch (actionMeta.action) {
case "create-option":
await RelationalService.createNoteIntoRelation(
const newNotePath = await RelationalService.createNoteIntoRelation(
tableColumn.config.related_note_path,
actionMeta.option.value
);
// Once the note is created, we need to update the value of the new option
const newOption = newValue.find(
(option) => option.value === actionMeta.option.value
);
if (newOption) {
newOption.value = newNotePath;
}
break;
default:
// Do nothing
Expand Down
7 changes: 5 additions & 2 deletions src/services/RelationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TableColumn } from "cdm/FolderModel";
import { LocalSettings } from "cdm/SettingsModel";
import { obtainColumnsFromFolder, obtainColumnsFromRows } from "components/Columns";
import { DatabaseCore, DEFAULT_SETTINGS } from "helpers/Constants";
import { resolve_tfile } from "helpers/FileManagement";
import { destination_folder, resolve_tfile } from "helpers/FileManagement";
import { adapterTFilesToRows } from "helpers/VaultManagement";
import { SMarkdownPage } from "obsidian-dataview";
import { dataApiBuilder } from "views/DataApiBuilder";
Expand Down Expand Up @@ -79,14 +79,17 @@ class RelationalServiceInstance {
* @param ddbbPath
* @param content
*/
public async createNoteIntoRelation(ddbbPath: string, newFilename: string): Promise<void> {
public async createNoteIntoRelation(ddbbPath: string, newFilename: string): Promise<string> {
LOGGER.info(`--> createNoteIntoRelation. Creating note ${newFilename} into relation ${ddbbPath}`);
const ddbbFile = resolve_tfile(ddbbPath);
const ddbbInfo = await new DatabaseInfo(ddbbFile, DEFAULT_SETTINGS.local_settings).build();
const dataApi = dataApiBuilder(ddbbFile, ddbbInfo.yaml.config.implementation);
const relatedColumns = await obtainColumnsFromFolder(ddbbInfo.yaml.columns);
await dataApi.create(newFilename, relatedColumns, ddbbInfo.yaml.config);
LOGGER.info(`<-- createNoteIntoRelation. Note ${newFilename} created into relation ${ddbbPath}`);
const dest_folder = destination_folder(ddbbFile, ddbbInfo.yaml.config);
const newNotePath = `${dest_folder}/${newFilename}.md`;
return newNotePath;
}

/**
Expand Down