Answer the question
In order to leave comments, you need to log in
Creating an object of a descendant class in Doctrine by a known field type (column_aggregation)
There is a project on Symfony (1.4) + Doctrine (1.2)
The project has the following class architecture: AbstractProduct, AlphaProduct, BetaProduct and GammaProduct classes are inherited from it, using column_aggregation and the 'type' field to distinguish between classes.
In one of the controllers, I need to create a new object of a known type. Those. (for example) if type 1 - you need to create AlphaProduct, 2 - BetaProduct, etc. Those. create a child object of the desired type from a known type.
At the moment it looks like this:
$classname = 'AbstractProduct';
foreach (Doctrine::getTable('AbstractProduct')->getOption('subclasses') as $subclass) {
$inheritanceMap = Doctrine::getTable($subclass)->getOption('inheritanceMap');
if ($inheritanceMap["type"] == $type) {
$classname = $subclass;
break;
}
}
$this->product = new $classname();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question