简体   繁体   中英

more on symfony2 doctrine and relations

So now I have set up my slideshow containers like: Geoarea, Building, Server

in different entities, mapped from one superclass.

Now the next problem I face is: I want to be able to relate these containers' contents to either one of the containers...

That was the reason I was initially just contemplating having one container entity and setting containertype with an INT flag, but OO-wise that isn't smooth or correct I think.

Now, I could of course have FK fields in my entity 'content' for each of the possible containers, and set them to nullable and only use one of them, but I feel like I am stuck in a rut here, think outside the box... I want to make fetching a container and it's related contents as simple as possible...

Each content is only related to ONE container, so having 3 FK-fields when never using more than one feels dumb...

You have two solutions. The first is to use Inheritance : Inheritance Mapping , but you will have some redundance in your database.

The second solution is to add a FK in your Child entity and not three in your Mother entity. Thereby, you will store common data in your Mother superclass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM