I have a page with a simple structure like this:
I wrote a query to get blocks whose parent is the “Members” block on the current page:
#+BEGIN_QUERY
{ :title "Current Members"
:query [:find (pull ?b [*])
:in $ ?current-page
:where
[?b :block/page ?p]
[?p :block/name ?current-page]
[?b :block/parent ?parent]
[?parent :block/content "Members"]]
:inputs [:current-page] }
#+END_QUERY
This query returns zero results. The way I understand how this query works is:
- The combination of
:inputs [:current-page]
and:in $ ?current-page
binds the variable?current-page
to whatever:current-page
is; I presume it’s the current page. -
[?b :block/page ?p]
constraints?p
to be a page on which blocks in the query (represented by?b
) will be found -
[?p :block/name ?current-page]
constraints?p
to be the current page, which in combination with the previous line, should constrain?b
to be only blocks that can be found on this page. -
[?b :block/parent ?parent]
constraints a new variable,?parent
, to be a parent of blocks represented by?b
-
[?parent :block/content "Members"]
constrains?parent
to be blocks that have the content “Members”. In combination with the previous constraint, this should mean that there is only one: the block containing the content “Members” on this page.
Since ?b
is constrained to blocks on ?p
, ?p
is constrained to be this page, ?parent
is constrained to be the “Members” block on this page, and the parent of ?b
is constrained to be the “Members” block on this page, then I would expect the output to be the three child blocks under the “Members” block. Where have I gone wrong in understanding how this query works?