Getting Second-Order Inlink / Nested Inlinks

Situation

There are a multiple instances where I’m looking for a second-order inline. The easiest to explain might be with how I would like to capture my reading:

At the moment, I’m working with three templates:

  1. Author
    1. Name → Filled in manually
    2. Books → via dataview query (basically FROM [[ ]] and specifying the note type as book)
    3. Quote → This is where my question comes in
  2. Book
    1. Book name → Manually filled in
    2. Author name → Selection via metadata menu from authors defined above
    3. Quote → via dataview query (basically FROM [[ ]] and specifying the note type as quote)
  3. Quote
    1. Content → Manually filled in
    2. Page Number → Manually filled in
    3. Chapter → Manually filled in
    4. Book → Selection via metadata menu from books defined above

Here as a graphic:

What I’m trying to do

All this works fine except getting the “Quote” into the author: What I’m looking for is how to create a second-order query, basically I’m looking for “Every quote of every book where of this author (name of the page).”

Things I have tried

Ideally, I could just nest, working with the FROM [[]] according to the doc and do a FROM [[[[]]]] but that gives a paring error. What I like about this expression is that it works with the implicit reference which should make it easy to work across my templates.

I had looked at what @holroy described in this post but it seems quite specific to this use case. I also had a look at this post from @renatomen but it also didn’t quite tackle what I’m trying to do.

Any pointers towards a solution would be appreciated – Thanks!

The gist of it would be:

  • List all quotes
  • Filter out all inlinks which are of type books → bookList
  • Filter bookList inlinks, and choose the name field or a specific author in this list

I can’t write a query suggestion as I don’t know any examples of neither of your files and field definitions. Could you give an example of a “Book Quote” note with corresponding “Book” and “Author” notes? Then possibly I or someone else could try building that query.

Hi @holroy, thanks for getting back!

Gladly provide some more information on how my notes look like (I’ve tried to simplify them to make the code clearer and have replaced triple ` with double):

Author Note

---
noteType: author
---

Author: AUTHOR NAME

## Books
``dataview
table
FROM [[]]
where
	noteType = "book"
``

## Quotes
``dataview
table
FROM [[ [[]] ]] <- Here is my challenge❗️
where
	noteType = "book-quote"
``

Book Note

---
noteType: book
---

Book: BOOK TITLE
Author: Author Name (multi selection via Metadata Menu from list of dv.pages('"Authors"'))

#### Quotes
``dataview
table
FROM [[]]
where
	noteType = "book-quote"

Book Quote

---
noteType: book-quote
---

Quote: 

Chapter Number: 

Page Number:

Book: Book Title (multi selection via Metadata Menu from list of dv.pages('"Books"'))

As you see, I’ve tried to work with FROM [[]] to make the references implicit and make the code simple and transferable. I wonder if there’s a way to do this also with the second order in-links.

I hope this gives you a good insight into how the notes look like and how I did the field definitions.

Thanks already for inquiring and helping making this a clearer post!

I’m assuming you’re using proper inline fields with double colons for all of those body field examples. And I’m also assuming just one quote per “Book Quote”. Based on that I’m kind of wondering why the “multi selection” on the “Book” field in a “Book Quote”. Can it be in multiple books?

Assuming that my assumptions were correct, try this query in your vault:

```dataview
TABLE file.outlinks, Book, Book.Book, Book.Author, Book.Author.noteType
WHERE noteType = "book-quote"
```

This should list all quotes with corresponding information. Dataview has some nifty lookup features builtin…

On a given Author page, you could the variant below to get all the quotes:

```dataview
TABLE file.outlinks, Book, Book.Book, Book.Author, Book.Author.noteType
WHERE noteType = "book-quote"
  AND contains(Book.Author, this.file.link)
```

This even allows for quotes from books where this author was a co-author. :slight_smile: Not sure how to it’ll behave if a quote is in multiple books…

The first query resulted in this display in my test vault:

The second query only those rows where “Author A” was present (that was from inside “Author A” of course.


The trick to why this actually works is that you can use a link to access it properties/fields directly. It can also works with multiple links, and accessing properties of those links, but that can get hairy very fast…

@holroy, thank you so much for sharing this. So if I understand you well, the first queries all book quotes and the second filters by the author through contains(Book.Author, this.file.link) → To get it right, it goes to the book note, search for author (Book.Author) and then check for an inlink from the current (author) note (this.file.link = current file name)?

In short: Thank you so much – Works like a dream.

If I may, two small questions that arise from this:

  1. Is there a way to create sections for each book?
  2. On how to include a note link when getting calling a field?
    • For context: When creating a book quote, I am prompted for the quote. This title then is prepended with the date as I do with most my notes, and I have the sanitised title-only version saved as alias for referencing and in short-name:
<%*  
let title = tp.file.title  
if (title.startsWith("Untitled")) {  
title = await tp.system.prompt("The book quote:");  
await tp.file.rename(title);  
}
%>
tags:
  - 
aliases:
  - <%* tR += title %>
  - 
noteType: book-quote
short-name: <%* tR += title %>
---
<%* await tp.file.move("/40 Resources/Book Quotes/" + tp.date.now() + " " + title )
%>

So my question is: How can I include the short-name (and not use the full file name with date) while including the link to the note?

Finally: Indeed, you were totally right with your assumptions about me using double colons for the body fields and having one quote per “Book Quote Note”. So indeed, it’s wrong to have a “multi selection” on the “Book” field in a “Book Quote”.

Tables in dataview are not good at sectioning, unless you start messing around with dataviewjs and splitting up the tables.

Given a link like Book, you can do link(Book, Book.short-name) (or possibly link(Book, Book["short-name"]) in some cases if it doesn’t like the dash… :slight_smile: ) to be the link for that book.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.