framework-web:symfony:models:relations

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
framework-web:symfony:models:relations [2018/02/16 11:59] – [Création] jcheronframework-web:symfony:models:relations [2019/08/31 14:21] (Version actuelle) – modification externe 127.0.0.1
Ligne 44: Ligne 44:
 === oneToMany === === oneToMany ===
  
-Chaque catégorie peut contenir plusieurs projets :+Chaque catégorie peut contenir plusieurs produits :
  
 <sxh php;tilte:src/Entity/Category.php> <sxh php;tilte:src/Entity/Category.php>
Ligne 75: Ligne 75:
 === Chargement === === Chargement ===
  
-**manyToOne** : Affichage de la catégorie d'un produit :+**manyToOne** : Récupération de la catégorie d'un produit :
  
-<sxh php;title:src/Controller/Products.php>+<sxh php;title:src/Controller/ProductController.php>
 use App\Entity\Product; use App\Entity\Product;
 // ... // ...
Ligne 94: Ligne 94:
  
 === Persistance === === Persistance ===
 +
 +Sauvegarde d'un produit et de sa catégorie
  
 <sxh php;title:src/Controller/ProductController.php> <sxh php;title:src/Controller/ProductController.php>
Ligne 107: Ligne 109:
      * @Route("/product", name="product")      * @Route("/product", name="product")
      */      */
-    public function index() +    public function index(){
-    {+
         $category = new Category();         $category = new Category();
         $category->setName('Computer Peripherals');         $category->setName('Computer Peripherals');
Ligne 131: Ligne 132:
     }     }
 } }
 +</sxh>
  
 +===== ManyToMany =====
 +Correspond aux associations non hiérarchiques de type CIM, __non porteuses de données__.\\
 +
 +==== Création ====
 +Exemple :
 +
 +<classdiagram>
 +[User]0..*-0..*[Group]
 +</classdiagram>
 +
 +<sxh php;title:app/Entity/User.php>
 +<?php
 +/** @Entity */
 +class User
 +{
 +    // ...
 +
 +    /**
 +     * Each User has Many Groups.
 +     * @ManyToMany(targetEntity="Group", inversedBy="users")
 +     * @JoinTable(name="users_groups")
 +     */
 +    private $groups;
 +
 +    public function __construct() {
 +        $this->groups = new \Doctrine\Common\Collections\ArrayCollection();
 +    }
 +
 +    // ...
 +}
 +</sxh>
  
  • framework-web/symfony/models/relations.1518778776.txt.gz
  • Dernière modification : il y a 6 ans
  • (modification externe)