0

I am looking for a little advice on database design.

I am constructing a slideshow applicatino on the symfony2 platform, and I have four different types of slideshow containers (company, geo-area, property and individual monitors). This is for the purpose of organizing content and inheriting content down the line (a monitor sits in a property, a property is part of a geoarea etc.).

Now, on flat PHP I would have used only two tables, "containers" and "contents", and put a type field in the containers table defining whether the container in question is a geo-area, property etc. and just linking each content piece (i.e. slide) with a FK to the appropriate container.

Now, learning about symfony2's entity system, it seems that I could gain a lot inheritance-wise by instead defining the different container types as separate entities, thus being able to fetch for instance the geo-area, and automatically get returned all of its child objects (all properties, and in turn all monitors belonging to that property) on the fly. I do however want to be able to switch the "belonging" of a content piece between different containers, and different container types. I sense this will be somewhat hairy with the described approach, seeing there will most likely be a problem with the relation (FK) of the content piece if it must have the capability of "belonging to" any of four different entiy types?

Someone seasoned in the symfony2 world could perhaps enlighten me as to the wisest path to proceed here?

1
  • Let me see... first, is essential that you think your business model in an object oriented way, not as a relational database. If you want that an entity has a property called container that can be of different type (and has different behaviors) you have a class inheritance issue. For example, you need the class Container that has the childs GeoArea, and so on. Then, you need to map the hierarchy to the database: docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/… Commented Jul 31, 2012 at 12:29

1 Answer 1

1

In our project we use Propel 1.6 and PropelBundle

Its syntax is quite developer-friendly. One great advantage of Propel is "fake" relations between tables. In your schema by just defining skipSql = true flag you omit the generation of FK, but one object can be fetched with another just by defined fake relation.

In your case it will end up with something like below:

$containers = ContainerQuery::create()->findByXXX('xxx');
$containers->getFirst()->getContents(); // Will return all joined content for the first container

During population of objects with related ones - you achieve great opportunity to use reverse relations:

$contents = $container->getContents();
$container = $contents->getContainer();

Just ask in comments, and I'll extend my answer with whatever you need ;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.