. */ namespace Doctrine\ORM\Persisters; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\DBAL\Types\Type; /** * Base class for entity persisters that implement a certain inheritance mapping strategy. * All these persisters are assumed to use a discriminator column to discriminate entity * types in the hierarchy. * * @author Roman Borschel * @author Benjamin Eberlei * @since 2.0 */ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister { /** * {@inheritdoc} */ protected function prepareInsertData($entity) { $data = parent::prepareInsertData($entity); // Populate the discriminator column $discColumn = $this->class->discriminatorColumn; $this->columnTypes[$discColumn['name']] = $discColumn['type']; $data[$this->getDiscriminatorColumnTableName()][$discColumn['name']] = $this->class->discriminatorValue; return $data; } /** * Gets the name of the table that contains the discriminator column. * * @return string The table name. */ abstract protected function getDiscriminatorColumnTableName(); /** * {@inheritdoc} */ protected function getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r') { $tableAlias = $alias == 'r' ? '' : $alias; $columnName = $class->columnNames[$field]; $columnAlias = $this->getSQLColumnAlias($columnName); $sql = $this->getSQLTableAlias($class->name, $tableAlias) . '.' . $this->quoteStrategy->getColumnName($field, $class, $this->platform); $this->rsm->addFieldResult($alias, $columnAlias, $field, $class->name); if (isset($class->fieldMappings[$field]['requireSQLConversion'])) { $type = Type::getType($class->getTypeOfField($field)); $sql = $type->convertToPHPValueSQL($sql, $this->platform); } return $sql . ' AS ' . $columnAlias; } /** * @param string $tableAlias * @param string $joinColumnName * @param string $className * * @return string */ protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $className) { $columnAlias = $this->getSQLColumnAlias($joinColumnName); $this->rsm->addMetaResult('r', $columnAlias, $joinColumnName); return $tableAlias . '.' . $joinColumnName . ' AS ' . $columnAlias; } }