In my database I have basically a table (entity for Doctrine
) called person and it looks like this:
class Person
{
private $id;
/**
* @ORM\ManyToOne(targetEntity="Person")
*/
private $parent;
}
I'd like to build a méthod getAllChildren
which returns all persons under person1
and recursively all persons under persons who have children.
I'd like to know if I can do this through one recursive SQL
request.
UPDATE1
postgres version: 9.1
-- Table: person
-- DROP TABLE person;
CREATE TABLE person
(
id serial NOT NULL,
parent_id integer,
nom character varying(255) DEFAULT NULL::character varying,
prenom character varying(255) DEFAULT NULL::character varying,
age integer,
description text,
statut character varying(255) DEFAULT NULL::character varying,
CONSTRAINT person_pkey PRIMARY KEY (id),
CONSTRAINT fk_7cbkzkd63HRzVK8e FOREIGN KEY (parent_id)
REFERENCES person(id) MATCH SIMPLE
)
UPDATE2
I've found http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/, this is pretty much what I need except my model is limitless