Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine how to setup Many to Many to Many relationship
    text
    copied!<p><strong>Summary</strong>: Using the following YML I get a reference to a FOREIGN KEY (role_id) that is not in my YML.</p> <p><strong>Problem</strong>: I'm trying to create a system where there is a user (CreditName) who can belong to many role's (all of which can have many users). There are also many projects, which can contain many User+Roles, so I'd like the Project to have a Many-to-Many relationship with the entry in the refclass for the Many-to-Many relationship between Users and Roles.</p> <p>Here's the relevant YML:</p> <pre><code>Project: columns: title: { type: string(255), notnull: true, unique: true } relations: CreditNameRoles: class: CreditNameRole refClass: ProjectCreditNameRole foreignAlias: Projects onDelete: CASCADE ProjectCreditNameRole: columns: project_id: { type: integer, primary: true } credit_name_role_id: { type: integer, primary: true } relations: Project: { foreignAlias: ProjectGenres, onDelete: CASCADE } CreditNameRole: { foreignAlias: CreditNameRole, onDelete: CASCADE } CreditName: columns: name: { type: string(255) } relations: Roles: class: Role refClass: CreditNameRole foreignAlias: CreditNames onDelete: CASCADE CreditNameRole: columns: id: { type: integer} credit_name_id: { type: integer, primary: true } role_id: { type: integer, primary: true } relations: CreditName: { foreignAlias: CreditNameRoles, onDelete: CASCADE } Role: { foreignAlias: CreditNameRoles, onDelete: CASCADE } Role: columns: name: { type: string(255) } </code></pre> <p>Using doctrine/symfony to try and use this YML to generate the database I get the following:</p> <pre><code>bash-3.2$ ./symfony doctrine:build --all --no-confirmation SQLSTATE[HY000]: General error: 1005 Can't create table 'database_name.#sql-68_148' (errno: 150). Failing Query: "ALTER TABLE credit_name_role ADD CONSTRAINT crpc FOREIGN KEY (role_id) REFERENCES project_credit_name_role(credit_name_role_id)". Failing Query: ALTER TABLE credit_name_role ADD CONSTRAINT crpc FOREIGN KEY (role_id) REFERENCES project_credit_name_role(credit_name_role_id) </code></pre> <p>Where is this 'FOREIGN KEY (role_id)' coming from and how do I correct it? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload