I am building a scheduler and task manager into a Symfony2 app. I currently have 4 task entities defined, let's call them Task A, Task B, Task C, and Task D - each has slightly different structure, which is why I broke them out into 4 separate entities rather than one entity and then leaving a bunch of columns blank.

My app allows users to create new Schedule entity/object, which will have various numbers of tasks A-D. What I need to do now is set up task dependencies. So Task A 3 might depend on the completion of Task B 2, and Task C 4 might depend on Task D 1.

I'm trying to figure out the best way of storing these dependencies; there will only ever be one dependency per task and it could be of any of the other three types. Will I require each task entity to have a column for the other tasks? For example: would the Task A entity need to have B Dependency, C Dependency, and D Dependency columns that I have to check individually? Or am I missing something that would let me store a relationship to an arbitrary entity in one column? I've looked at Doctrine's object type, but I'm not sure what that would look like when I get it back out. Would I know what kind of object it was when it went in?

有帮助吗?

解决方案

I don't think you want to use the object type - that is a serialized php object.

If your different tasks are truly only slightly different in structure, you could use single table inheritance to keep all of your tasks in one table, and then use a self referencing one-to-one relationship to manage the dependency. Yes, the table would have extra null columns for different task types but your actual entities would be independent of one another.

There are some considerations for inheritance mapping strategies outlined here: http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html#single-table-inheritance

The self referencing association is demonstrated in the Doctrine docs here: http://docs.doctrine-project.org/en/latest/reference/association-mapping.html#one-to-one-self-referencing

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top