Reputation: 641
I am stuck at this question where I am turning my Class Diagram into symfony code. I have a Project class and a ProjectType class. Normally you would say a project IS of a certain project type so that would imply inheritance (IS A) relationship. Now doctrine states about inheritance:
A mapped superclass is an abstract or concrete class that provides persistent entity state and mapping information for its subclasses, but which is not itself an entity.
The idea is that different project types can be made (they should be manageable). If doctrine says in this example that ProjectType is not an entity then I can't instantiate them. So I thought of a OneToMany assocation. Is this correct OOP?
Upvotes: 0
Views: 78
Reputation: 1431
You can specify the relation between entities in an abstract class, If the relationship changes in the concrete entity you can overwrite it.
For example you have an abstract class called Project, that has a many to on relationship with ProjectType.
Then you create two entities extending from Project called GreenProject and RedProject. GreenProject only can have one ProjectType associated so the relationship defined in the base class is ok.
Them RedProject can have more than one ProjectType so is a ManyToMany relationship. Then you have to overwrite the existing relationship in the base class by redeclaring the $projectType property in the RedProject class and using the apropiate annotations.
You can distribute your superclases within a bundle for instance, and the use them extending them in your AppBundle. This is usedby FosUserBundle (User class), FosOauthBundle (Client and Token classes for instance) and others.
Upvotes: 1