I need to display a tree of categories by levels (all tree elements on each level).
Root
Cat1 (parent_id) Cat2 (parent_id) ...
Subcat1 (parent_id) Subcat2 (parent_id) Subcat3 (parent_id) ...
I tried to implement it with Nested Set structure, but I ran into a problem: no easy way to get the parent's node id (without a separate query to the database). Should I use Adjacency list instead?
The goal is to make the display as fast as possible, ideally with one query to the database.
Read this article about Nested Set vs Adjacency List. You'll see that Nested Set makes the queries faaaaar easier to write. Also read this § about the nested set hierarchy hydration method, and you'll figure out how to get several doctrine objects in a hierarchical form with a single query.