#+BEGIN_QUERY
{:title "All blocks with tag inbox"
:query [:find (pull ?b [*])
:where
[?p :block/name "inbox"]
[?b :block/refs ?p]]
}
#+END_QUERY
It works fine:
But in table view, i see only blocks:
How render only page titles in table view mode? I also see that the results in table / non-table view mode are sorted differently, how can I achieve the same sorting. Thanks in advance for your help.
If i understand correctly you have a page that has a link to the page inbox and you want to grab that page and not the block which references inbox.
If so, here’s what you are looking for:
#+BEGIN_QUERY
{:title "All blocks with tag inbox"
:query [:find (pull ?p [*])
:where
[?i :block/name "inbox"]
[?b :block/refs ?i]
[?b :block/page ?p]
]
}
#+END_QUERY
Same problem here.
Thanks @Siferiax . @Xardas solution outputs the blocks that link to “inbox”. Your solution outputs the pages linking to “inbox”. Is there a way to have best of both worlds? I.e. get all blocks, but with an additional table column “page title”, that shows, to which page each block belongs?
Yes, to turn that raw data into something more readable I made a custom table using :view.
The different return values get bound to keys (from the :find and :keys sections)
And then used in the :view to display them more nicely.
As you concluded correctly pages and blocks are different, most notable for this situation in their default result-transform and view used for :find (pull ?b [*]) (or ?p). Putting something different in :find will stop the default from working as intended and thus giving unexpected output.
At least that’s my interpretation.
@ste my goal is one page for each todo and first page block for status. You solution is nice, but I will have to duplicate the page title in the first block. @Siferiax you solution works perfect. Thanks guys.
There’s an alternative way thanks to Darwis on discord:
Makes the query a bit more concise and allows for the default table view usage.
I took their example from discord and applied it to the query I made for this thread.
The query basically adds another property to the block so it can be used in the table view.
:journal is what is used as a name for page. Please be aware that :page is reserved and doesn’t work.
#+BEGIN_QUERY
{:title "All blocks with tag inbox"
:query [:find (pull ?b [*])
:where
[?i :block/name "inbox"]
[?b :block/refs ?i]
]
:result-transform (fn [res] (sort-by (fn [s] (get-in s [:block/properties :journal-day])) > (map (fn [m]
(update m :block/properties
(fn [u] (assoc u :journal-day (get-in m [:block/page :block/journal-day]) :journal (get-in m [:block/page :block/name]))
))
) res)))
}
#+END_QUERY