Différences
Ci-dessous, les différences entre deux révisions de la page.
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] jcheron | framework-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 | + | Chaque catégorie peut contenir plusieurs |
<sxh php; | <sxh php; | ||
Ligne 75: | Ligne 75: | ||
=== Chargement === | === Chargement === | ||
- | **manyToOne** : Affichage | + | **manyToOne** : Récupération |
- | <sxh php; | + | <sxh 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; | <sxh php; | ||
Ligne 107: | Ligne 109: | ||
* @Route("/ | * @Route("/ | ||
*/ | */ | ||
- | public function index() | + | public function index(){ |
- | | + | |
$category = new Category(); | $category = new Category(); | ||
$category-> | $category-> | ||
Ligne 131: | Ligne 132: | ||
} | } | ||
} | } | ||
+ | </ | ||
+ | ===== ManyToMany ===== | ||
+ | Correspond aux associations non hiérarchiques de type CIM, __non porteuses de données__.\\ | ||
+ | |||
+ | ==== Création ==== | ||
+ | Exemple : | ||
+ | |||
+ | < | ||
+ | [User]0..*-0..*[Group] | ||
+ | </ | ||
+ | |||
+ | <sxh php; | ||
+ | <?php | ||
+ | /** @Entity */ | ||
+ | class User | ||
+ | { | ||
+ | // ... | ||
+ | |||
+ | /** | ||
+ | * Each User has Many Groups. | ||
+ | * @ManyToMany(targetEntity=" | ||
+ | * @JoinTable(name=" | ||
+ | */ | ||
+ | private $groups; | ||
+ | |||
+ | public function __construct() { | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | // ... | ||
+ | } | ||
+ | </ | ||