TreeBehavior matching and notMatching combined

I got the following DB schema: Domains HABTM Categories

and the Categories Table has the TreeBehavior attached to it with data like

  • Parent-Category 1
    • Name1
    • Name2
  • Parent-Category 2
    • Plugin1
    • Plugin2

Now I would like to get all Domains which have

  • Parent-Category 1 => Name1 set and
  • have nothing set from any of the Parent-Category 2 Sub Categories (1 level is fine, not multiple levels down)

I know how I can get the first condition which is just a simple ->matching() but I am a bit stuck on the second.

Normally I would go for a ->notMatching() but I can’t combine those 2 together.

Is there an easy way to do that?

I solved it via a subquery :smile: