Although Symfony and Doctrine are very intuitive when it comes to detecting many-to-many(M:N) relationships and generating the relevant forms, there was one situation I encountered where I found myself looking for an alternative solution. Take, for instance, the following Doctrine schema for a simple project management system:
# config/doctrine/schema.yml
Project:
columns:
name: { type: string(255), notnull: true, unique: true }
relations:
Users:
refClass: ProjectUser
class: User
local: project_id
foreign: user_id
User:
columns:
username: { type: string(255), notnull: true, unique: true }
relations:
Projects:
refClass: ProjectUser
class: Project
local: user_id
foreign: project_id
Role:
columns:
name: { type: string(255), notnull: true, unique: true }
ProjectUser:
columns:
user_id: { type: integer, notnull: true, primary: true }
project_id: { type: integer, notnull: true, primary: true }
user_role_id: { type: integer, notnull: true }
relations:
Role:
class: Role
local: user_role_id
foreign: id
Project:
class: Project
local: project_id
foreign: id
User:
class: User
local: user_id
foreign: id
