Voici comment se traduit les différentes associations de type One-To-One :

Voici le code PHP produit :
<?php namespace org\rapidoo\demo\onetoone; //------------------------------------------- // One-to-one mono navigable with 1 key //------------------------------------------- class A { /** * The id property. * @var int */ private $id; /** * The name property. * @var B */ private $b; } class B { /** * The id property. * @var int */ private $id; } //------------------------------------------- // One-to-one binavigable with 2 keys //------------------------------------------- class C { /** * The id property. * @var int */ private $id; /** * The name property. * @var D */ private $d; } class D { /** * The id property. * @var int */ private $id; /** * The name property. * @var C */ private $c; } //------------------------------------------- // One-to-one binavigable with 1 key //------------------------------------------- class E { /** * The id property. * @var int */ private $id; /** * The name property. * @var F */ private $f; } class F { /** * The id property. * @var int */ private $id; /** * The name property. * @var E */ private $e; } ?>
Le code de mapping relationnel
<?xml version="1.0" encoding="UTF-8"?> <mapping xmlns="http://schema.emukina.fr/Mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.emukina.fr/Mapping http://schema.emukina.fr/Mapping.xsd" package="org.rapidoo.demo.onetoone"> <!-- One-to-one mono navigable with 1 key --> <class name="A" table="a"> <id> <property name="id" column="id_a"/> </id> <one-to-one name="b" column="id_b" type="B" not-null="true"/> </class> <class name="B" table="b"> <id> <property name="id" column="id_b"/> </id> </class> <!-- One-to-one bi navigable with 2 keys --> <class name="C" table="c"> <id> <property name="id" column="id_c"/> </id> <one-to-one name="d" column="id_d" type="D" not-null="true"/> </class> <class name="D" table="d"> <id> <property name="id" column="id_d"/> </id> <one-to-one name="c" column="id_c" type="C" /> </class> <!-- One-to-one bi navigable with 1 key --> <class name="E" table="e"> <id> <property name="id" column="id_e"/> </id> <one-to-one name="f" column="id_f_fk" type="F" not-null="true"/> </class> <class name="F" table="f"> <id> <property name="id" column="id_f"/> </id> <one-to-one name="e" column="id_f" reverse-column="id_f_fk" type="E" not-null="true"/> </class> </mapping>
Et enfin le code Sql
--------------------------------------------- -- One-to-one mono navigable with 1 key --------------------------------------------- CREATE TABLE `a` ( `id_a` INT UNSIGNED AUTO_INCREMENT, `id_b` INT UNSIGNED NOT NULL, PRIMARY KEY(`id_a`), INDEX `IDX_a_b`(`id_b`) , CONSTRAINT `FK_a_b` FOREIGN KEY (`id_b`) REFERENCES `b`(`id_b`) ); CREATE TABLE `b` ( `id_b` INT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(`id_b`) ); --------------------------------------------- -- One-to-one binavigable with 2 keys --------------------------------------------- CREATE TABLE `c` ( `id_c` INT UNSIGNED AUTO_INCREMENT, `id_d` INT UNSIGNED NOT NULL, PRIMARY KEY(`id_c`), INDEX `IDX_c_d`(`id_d`) , CONSTRAINT `FK_c_d` FOREIGN KEY (`id_d`) REFERENCES `d`(`id_d`) ); CREATE TABLE `d` ( `id_d` INT UNSIGNED AUTO_INCREMENT, `id_c` INT UNSIGNED NULL, PRIMARY KEY(`id_d`), INDEX `IDX_d_c`(`id_c`) , CONSTRAINT `FK_d_c` FOREIGN KEY (`id_c`) REFERENCES `c`(`id_c`) ); --------------------------------------------- -- One-to-one binavigable with 1 key --------------------------------------------- CREATE TABLE `e` ( `id_e` INT UNSIGNED AUTO_INCREMENT, `id_f_fk` INT UNSIGNED , PRIMARY KEY(`id_e`), INDEX `IDX_e_f`(`id_f_fk`) , CONSTRAINT `FK_e_f` FOREIGN KEY (`id_f_fk`) REFERENCES `f`(`id_f`) ); CREATE TABLE `f` ( `id_f` INT UNSIGNED AUTO_INCREMENT, PRIMARY KEY(`id_f`) );