sql - Get the root node in closure table with Doctrine -


i have following following closure table:

enter image description here

what want rows have no ancestors (root node).

in picture above want first row only.

i tried following dql:

public function findallrootgroups() {     $subquery =  $this->createquerybuilder('c')         ->select('c')         ->where('c.depth > 0');      $query = $this->createquerybuilder('c2');     $query->where($query->expr()->notin('c2.id', $subquery->getdql()));      $roots = $query->getquery()->getresult();      echo '<pre>'; \doctrine\common\util\debug::dump($roots); echo '</pre>';die; } 

but returned rows depth = 0.

so, how can root nodes only?

thanks.

it looks you've search on rows have same ancestor_id, descendant_id id , have depth of 0

$this->createquerybuilder('c')         ->where('c.ancestorid = c.id')         ->andwhere('c.descendantid = c.id')         ->andwhere('c.depth = 0') ; 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

elasticsearch python client - work with many nodes - how to work with sniffer -

delphi - Disable and change color of node in Treeview -