framework-web:symfony:models:relations

Ceci est une ancienne révision du document !


Relations

2 grands types de relations existent :

  • manyToOne/oneToMany
  • manyToMany

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.

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;
    }
}

  • framework-web/symfony/models/relations.1518776095.txt.gz
  • Dernière modification : il y a 6 ans
  • (modification externe)