Exemple de relation entre entités Doctrine dans Symfony
Relation « unique » (ManyToOne) entre « Child » et « School »
//coté Child
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\School", inversedBy="children")
* @ORM\JoinColumn(name="school_id", referencedColumnName="id", nullable=false)
*/
protected $school;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\School", inversedBy="children")
* @ORM\JoinColumn(name="school_id", referencedColumnName="id", nullable=false)
*/
protected $school;
//coté School
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Child", mappedBy="school")
*/
protected $children;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Child", mappedBy="school")
*/
protected $children;
Relation « multiple » (ManyToMany) entre « Child » et « Member »
//coté Child
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Member", inversedBy="children")
*/
protected $members;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Member", inversedBy="children")
*/
protected $members;
//coté Member
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Child", mappedBy="members")
*/
protected $children;
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Child", mappedBy="members")
*/
protected $children;