I want to get roots of tree in database, it works correctly but problem is here that it query database 500 times for 500 nodes, is there a way to improve this?
$query = $this->createQueryBuilder('n')
->where('n.parent IS NULL')
->getQuery();`
entity structure:
Radio\ArchiveBundle\Entity\Category:
type: entity
table: null
repositoryClass: Radio\ArchiveBundle\Repository\CategoryRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
isActive:
type: boolean
nullable: true
oneToMany:
tracks:
targetEntity: Radio\ArchiveBundle\Entity\Track
mappedBy: category
manyToOne:
parent:
targetEntity: Radio\ArchiveBundle\Entity\Category
inversedBy: childrens
fetch: EAGER
oneToMany:
childrens:
targetEntity: Radio\ArchiveBundle\Entity\Category
mappedBy: parent
cascade: [persist, remove]
Symfony2 profiler image: