- 1
[Opened] Gerer plusieurs cles etrangères provenant d'un même table dans un crud
Posted by info2012 on 10/16/2014 11:28
Bonjour,
j'ai une table echantillon (id_echantillon, nom_echantillon, poids_echantillon, cle_unite_poids_echantillon, volume_echantillon, cle_unite_volume_echantillon, surface_echantillon, cle_unite_surface_echantillon), et une table unité (id_unite, nom unite) qui est liée à la table echantillon par les champs cle_unite_poids, cle_unite_volume_echantillon et cle_unite_surface_echantillon Mon dao est écrit comme ceci:
<datasources>
<primarytable name="echantillons" realname="echantillons" primarykey="id_echantillon" />
<optionnalforeigntable name="unites" realname="unites" primarykey="id_unite" onforeignkey="cle_unite_poids_echantillon" />
<optionnalforeigntable name="unites" realname="unites" primarykey="id_unite" onforeignkey="cle_unite_volume_echantillon" />
<optionnalforeigntable name="unites" realname="unites" primarykey="id_unite" onforeignkey="cle_unite_surface_echantillon" />
</datasources>
<record>
<property name="id_echantillon" fieldname="id_echantillon" datatype="int" autoincrement="true" default=""/>
<property name="nom_echantillon" fieldname="nom_echantillon" datatype="varchar" maxlength="250"/>
<property name="poids_echantillon" fieldname="poids_echantillon" datatype="float"/>
<property name="volume_echantillon" fieldname="volume_echantillon" datatype="float"/>
<property name="surface_echantillon" fieldname="surface_echantillon" datatype="float"/>
<property name="cle_unite_poids_echantillon" fieldname="cle_unite_poids_echantillon" datatype="int"/>
<property name="nom_unite" fieldname="nom_unite" datatype="character varying" maxlength="150" table="unites" />
<property name="cle_unite_volume_echantillon" fieldname="cle_unite_volume_echantillon" datatype="int"/>
<property name="cle_unite_surface_echantillon" fieldname="cle_unite_surface_echantillon" datatype="int"/>
</record>
Le champ
<property name="nom_unite" fieldname="nom_unite" datatype="character varying" maxlength="150" table="unites" />
m'affiche une erreur (nom de table inconnue pour la propriété nom_unite)
Je peux parfaitement retirer ce champs du dao, mais si je le fait, je ne pourrait plus afficher le nom des unités dans la liste des échantillons:
protected $propertiesForList = array('nom_echantillon', 'num_echantillon', 'poids_echantillon' ,'nom_unite', 'volume_echantillon' ,'nom_unite', 'surface_echantillon','nom_unite');
Merci beaucoup.
Bonne journée
[Opened] Gerer plusieurs cles etrangères provenant d'un même table dans un crud
Posted by laurentj on 11/25/2014 11:43
Bonjour,
Tu as plusieurs jointures sur la même table : il faut donc en SQL donner des alias différents à ta table unite pour chaque jointures. Donc un nom différent au optionalforeigntable
<datasources>
<primarytable name="echantillons" realname="echantillons" primarykey="id_echantillon" />
<optionnalforeigntable name="unites1" realname="unites" primarykey="id_unite" onforeignkey="cle_unite_poids_echantillon" />
<optionnalforeigntable name="unites2" realname="unites" primarykey="id_unite" onforeignkey="cle_unite_volume_echantillon" />
<optionnalforeigntable name="unites3" realname="unites" primarykey="id_unite" onforeignkey="cle_unite_surface_echantillon" />
</datasources>
Et bien sûr indiquer le bon nom de table dans les propriétés.
- 1

