Does someone know, whether it’s possible to query for pages that are co-listed in a specific property of any page/block?
So, for instance, we have a block
- block
authors:: [[Alice]], [[Bob]]
and we want to query for all pages, that occur in the authors
property together with Alice
(so here our output should be Bob
).
As the example implicates, one could use such a query to list all co-authors
My failed attempt:
#+BEGIN_QUERY
{:title "Co-Authors"
:query [:find (pull ?b [*])
:where
[?h :block/properties ?prop]
[(get ?prop :authors) ?v]
[(contains? ?v ?b)]
[(contains? ?v "Alice")]
]}
#+END_QUERY
As I understand, contains?
does not bind the variable ?b
, that’s why this doesn’t work.
Other failed attempt:
I tried to use the functions, and get at least a string with all the authors together (multiple times and with Alice
included), but it didn’t work as well
I get a syntax error
- #+BEGIN_QUERY
{:title "Work"
:query [:find (pull ?h [*])
:where
[?h :block/properties ?prop]
[(get ?prop :authors) ?v]
[(contains? ?v "Alice")]
]}
#+END_QUERY
- {{function (print-str (concat (fn [x] (:authors x) result)))}}
Note: the Work
-query itself returns all blocks with Alice
listed under authors
Obsidian Dataview Version
Don’t know, whether this helps, but here is a Dataview-js version of the wanted query:
let me = "Alice"
let relatedAuthors = dv.pages()
.where(b => b.author)
.where(b => b.author
.map(x => String(x) === me)
.includes(true))
.author
.map(x => String(x))
.where(x => x !== me)
.distinct()
dv.list(
relatedAuthors.map(x => dv.fileLink(x, false, x))
)