Ceci est une ancienne révision du document !
Relations
2 grands types de relations existent :
- manyToOne/oneToMany
- manyToMany
manyToOne/oneToMany
Correspond aux associations hiérarchiques de type CIF.
manyToOne et oneToMany correspondent au même type d'association, mais vus de chaque côté de la relation.
manyToOne
Exemple
<yuml> [Product]0..*-1[Category] </yuml>
Chaque produit appartient à une catégorie :
// ...
class Product{
// ...
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="products")
* @ORM\JoinColumn(nullable=true)
*/
private $category;
public function getCategory(): Category
{
return $this->category;
}
public function setCategory(Category $category)
{
$this->category = $category;
}
}