Is there a way to return nodes based on id

I have created a tree from a mySQL table.

From the ID is there a way to return all the ID’s back to the root (first ID) so it returns a list:


There is a method getParentId() … etparentid
You just get all the ids untill you’ll get the root ID ‘0’ and replace the order of this list items.