Bonjour à tous,

Alors pour une rapide présentation, je suis actuellement en train d'apprendre à utiliser symfony. Pour cela, j'ai rapidement lu et réaliser une partie du tutoriel 'Jobeet'. Je réalise maintenant un projet personelle.
J'ai donc élaborer un modèle, j'ai ensuite générer automatiquement le schema.yml mais comme les clés étrangères n'étaient pas prise en compte, j'ai repris à la main ce fichier.
Cependant, et c'est la que les ennuis commencent, j'ai un problême au niveau des contraintes de deux tables liées entre elles par une clé étrangère.

Pour le SGBDR, j'utilise PostGreSql.

Voici le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
El_Candidats:
  connection: doctrine
  tableName: el_candidats
  columns:
    cotisant_id: { type: integer(4) , primary: true }
    poste_id: { type: integer(4), primary: true }
    description: { type: integer(4), notnull: true }
  relations:
    Co_Cotisants: { onDelete: CASCADE, onUpdate: CASCADE, local: cotisant_id, foreign: id, type: one, foreignType: many }
    El_Postes: { onDelete: CASCADE, onUpdate: CASCADE, local: poste_id, foreign: id, type: one, foreignType: many }
 
El_Postes:
  connection: doctrine
  tableName: el_postes
  columns:
    id: { type: integer(4), primary: true }
    description: { type: string(), notnull: true }
 
El_Votes:
  connection: doctrine
  tableName: el_votes
  columns:
    poste_id: { type: integer(4), primary: true }
    cotisant_id: { type: integer(4), primary: true }
    candidat_id: { type: integer(4), primary: true }
  relations:
    Co_Cotisants: { onDelete: CASCADE, onUpdate: CASCADE, local: cotisant_id, foreign: id, type: one, foreignType: many }
    El_Postes: { onDelete: CASCADE, onUpdate: CASCADE, local: poste_id, foreign: id, type: one, foreignType: many }
    El_Candidats: { onDelete: CASCADE, onUpdate: CASCADE, local: candidat_id, foreign: cotisant_id, type: one, foreignType: many }
Et voici le SQL généré par la commande 'symfony doctrine:build --all':
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
CREATE TABLE el_candidats (poste_id SERIAL, cotisant_id INT, description INT NOT NULL, PRIMARY KEY(poste_id, cotisant_id));
CREATE TABLE el_postes (id SERIAL, description TEXT NOT NULL, PRIMARY KEY(id));
CREATE TABLE el_votes (poste_id SERIAL, cotisant_id SERIAL, candidat_id INT, PRIMARY KEY(poste_id, cotisant_id, candidat_id));
ALTER TABLE el_candidats ADD CONSTRAINT el_candidats_poste_id_el_postes_id FOREIGN KEY (poste_id) REFERENCES el_postes(id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE el_candidats ADD CONSTRAINT el_candidats_cotisant_id_el_votes_candidat_id FOREIGN KEY (cotisant_id) REFERENCES el_votes(candidat_id) NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE el_candidats ADD CONSTRAINT el_candidats_cotisant_id_co_cotisants_id FOREIGN KEY (cotisant_id) REFERENCES co_cotisants(id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE el_votes ADD CONSTRAINT el_votes_poste_id_el_postes_id FOREIGN KEY (poste_id) REFERENCES el_postes(id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE el_votes ADD CONSTRAINT el_votes_cotisant_id_co_cotisants_id FOREIGN KEY (cotisant_id) REFERENCES co_cotisants(id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE el_votes ADD CONSTRAINT el_votes_candidat_id_el_candidats_cotisant_id FOREIGN KEY (candidat_id) REFERENCES el_candidats(cotisant_id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
J'ai alors plusieurs questions :
  1. Pourquoi la commande SQL suivante est généré
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ALTER TABLE el_candidats ADD CONSTRAINT el_candidats_cotisant_id_el_votes_candidat_id FOREIGN KEY (cotisant_id) REFERENCES el_votes(candidat_id) NOT DEFERRABLE INITIALLY IMMEDIATE;
    alors que nul part dans mon schema.yml, il y a une contrainte de clé étrangère de el_candidats vers el_votes ...
  2. Je voulais savoir si il était possible que les deux colonnes concerné soit de type différent (INT et SERIAL dans mon cas)


De plus lorsque j'essaye d'éxecuter ce code, j'obtient l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
SQLSTATE[42830]: Invalid foreign key: 7 ERREUR:  il n'existe aucune contrainte unique correspondant aux clés données pour la table « el_votes » référencée.
Failing Query: "ALTER TABLE el_candidats ADD CONSTRAINT el_candidats_cotisant_id_el_votes_candidat_id FOREIGN KEY (cotisant_id) REFERENCES el_votes(candidat_id) NOT DEFERRABLE INITIALLY IMMEDIATE".
Si vous voulez me poser des questions supplémentaires, n'hésitez pas.
Inarius