Doctrine2 ORMs have 2 technical ways to handle many-to-many associations:
1 / For a βsimpleβ connection between two objects and without an additional attribute:
- Use @ManyToMany associations between objects
- In this case, the link table is used directly, without an association object.
2 / When the link table introduces additional fields or more than two objects:
- Use an association class , that is, a "real" object, to map a reference table
- In this case, the direct ManyToMany association is replaced by OneToMany / ManyToOne associations between the participating objects.
These 2 implementations are completely different.
But in some cases of future business requirements, you may quickly need to change simple associations by adding additional fields, for example. In this case, we must replace the direct ManyToMany associations in existing objects with a second implementation code and refactoring.
- So, is this a good way to always use union objects to handle all many associations?
- Otherwise, what are the best practices for choosing a good implementation and managing this kind of domain evolution model?
source share