# Why are file links being created when IDs exist?

**URL:** <https://org-roam.discourse.group/t/why-are-file-links-being-created-when-ids-exist/1395>\
**Category:** Troubleshooting\
**Created:** [March 23, 2021, 3:33am UTC](https://org-roam.discourse.group/t/why-are-file-links-being-created-when-ids-exist/1395 "2021-03-23T03:33:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gcoladon](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gcoladon/32/976_2.png) [@gcoladon](https://org-roam.discourse.group/u/gcoladon)\
**Post date:** [March 23, 2021, 3:33am UTC](https://org-roam.discourse.group/t/why-are-file-links-being-created-when-ids-exist/1395/1 "2021-03-23T03:33:44Z")

</div>

Following the inspiration of [this post](https://org-roam.discourse.group/t/org-roam-major-redesign/1198/26), I have been trying to use only ID links in my `org-roam` files. I have `org-roam-prefer-id-links` set to `t`. And my `org-roam-capture-templates` put an ID property at the top of every new file.

But when I create a new file `testa` a via `org-roam-find-file`, and then in `filea` I call `org-roam-insert`, what’s inserted is a `file:` link.

```auto
:PROPERTIES:
:ID: 2021_0322_201447
:END:
#+title: testa

[[file:2021_0322-testb.org][testb]]

```

```auto
:PROPERTIES:
:ID: 2021_0322_201506
:END:
#+title: testb

```

I see that in the implementation of `org-roam-insert` that the 5th optional argument is link-type:

`(defun org-roam-insert (&optional lowercase completions filter-fn description link-type)`

which defaults to type `file:`:

`LINK-TYPE is the type of link to be created. It defaults to \"file\".`

Am I wrong to think that org-roam-prefer-id-links should override this default and produce an ID link in this case? Or is that effect achievable via some sort of alternative configuration I’m as-yet unaware of?

---

<div class="post-metadata">

**Author:** ![jethro](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@jethro](https://org-roam.discourse.group/u/jethro)\
**Post date:** [March 23, 2021, 6:05am UTC](https://org-roam.discourse.group/t/why-are-file-links-being-created-when-ids-exist/1395/2 "2021-03-23T06:05:16Z")

</div>

This is likely because your database isn’t synced yet, so Org-roam thinks the ID doesn’t exist.

```auto
(setq org-roam-db-update-method 'immediate)

```

Should alleviate some of the surprises.

---

<div class="post-metadata">

**Author:** ![gcoladon](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/gcoladon/32/976_2.png) [@gcoladon](https://org-roam.discourse.group/u/gcoladon)\
**Post date:** [March 23, 2021, 7:48pm UTC](https://org-roam.discourse.group/t/why-are-file-links-being-created-when-ids-exist/1395/3 "2021-03-23T19:48:39Z")

</div>

Thank you for the suggestion, Jethro. (and thank you and Zaeph and everyone else for org-roam! :))

Even with `(setq org-roam-db-update-method 'immediate)` I was still getting occasional file: links, and then I happened upon what I think solved the problem: when I save the capture buffer (C-x C-s) before exiting out of it (C-c C-c), the link in the referring document always ends up being an id: link, but when I don’t save first, it is always a file: link.

So, I hypothesize that the order of operations on leaving the capture buffer is such that, the link is generated for the new file prior to the file being saved and the database being updated?

Whether that hypothesis is correct or not – apparently now all I need to remember to do is C-x C-s before exiting the capture buffer, and I will end up with id: links as desired.

Thanks again

---

<div class="post-metadata">

**Author:** ![jethro](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@jethro](https://org-roam.discourse.group/u/jethro)\
**Post date:** [March 24, 2021, 5:14am UTC](https://org-roam.discourse.group/t/why-are-file-links-being-created-when-ids-exist/1395/4 "2021-03-24T05:14:16Z")

</div>

> [@gcoladon](#):
>
> Even with `(setq org-roam-db-update-method 'immediate)` I was still getting occasional file: links, and then I happened upon what I think solved the problem: when I save the capture buffer (C-x C-s) before exiting out of it (C-c C-c), the link in the referring document always ends up being an id: link, but when I don’t save first, it is always a file: link.

Org-roam operates on the file state on-disk. If you don’t save the file after capture, then to Org-roam, the file isn’t updated yet, and the database also won’t be. That’s the trouble with this sort of dual representation.
