Query to exclude blocks already on page by block-ref

I am trying to have a query exclude blocks that have a block-ref on a page. Does someone know how I can update the search query below to cover this usecase? Any tips, pointers, etc are greatly appreciated.

SCENARIO

Journal: Monday

TODO Aaaa

Journal: Wednesday

TODO Bbb

Page: Contents

block-ref ((xx-xx-xx-xx)) of “TODO Aaaa”

Query all TODOs excluding those with block-ref in contents

Wanted results

  • TODO Bbbb

Not wanted results

  • TODO Aaaa
  • TODO Bbbb

CURRENT SEARCH

#+BEGIN_QUERY
{
    :query [
        :find (pull ?b [*])
        :where
            [?b :block/uuid]
            [?b :block/marker ?marker]
            [(contains? #{"TODO" "DOING" "LATER" "NOW"} ?marker)]
            (not [?b :block/path-refs [:block/name "contents"]])
    ]
}
#+END_QUERY

ATTEMPTED SERACHES

I’m no expert in advanced searches, but I’m trying.

2

The block pulled has an ID within its properties once it’s referenced elsewhere by block-ref. It seems that a search of “contents” for the pulled blocks ID is needed. If that matches, exclude. So I was thinking along the lines of this.

            (not [?b :block/uuid [:block/content "contents"]]) 

However, I don’t fully understand this pattern procedurally. Does this pull the block ?b, get the ID of the block :block/uuid, then check the contents of “contents” :block/content "contents", applying the not match (not [..])?

1

Looking at this structure I see other options for the exclusion, but they did not result in the desired outcome. logseq/db_schema.cljs

#+BEGIN_QUERY
{
	:query [
		:find (pull ?b [*]) 
		:where 
			[?b :block/uuid] 
			[?b :block/marker ?marker] 
			[(contains? #{"TODO" "DOING" "LATER" "NOW"} ?marker)] 
			(not [?b :block/path-refs [:block/name "contents"]])
			(not [?b :block/refs [:block/name "contents"]])
			(not [?b :block/page [:block/name "contents"]]) 
			(not [?b :block/alias [:block/name "contents"]]) 
	]
}
#+END_QUERY

WHY

I like to keep all my todo’s in a single place, where I can see them together, not spread across journals or pages. That is how I use contents, as a todolist. I separate out the todos into different levels (Backlog, On-hold, Up Next, Doing). I want a search to be able to find all todo’s that I haven’t put into the contents page via the block-ref. I don’t want to move the original todo, so using block-ref, as that would break part of the usecase of LogSeq being able to graph my data over time across the journal dates, project pages, etc. If there is a better way I’m open to this also. I put the search under “Discovered ToDos”.