Open
Description
Feature Request
Q | A |
---|---|
New Feature | yes |
RFC | no |
BC Break | yes |
Summary
I'm trying to implement NamingStrategy so that every field will be prefixed with a table name, the reason I do that is because I use NativeQuery a lot, but it requires me to manually set aliases in ResultSetMapping aswell as in SQL, when there's multiple joins it becomes really difficult to manage.
Now referenceColumnName
takes no arguments so it is impossible to know what Entity's reference column we are trying to generate.
class TablePrefixNamingStrategy implements NamingStrategy
{
/**
* @var UnderscoreNamingStrategy
*/
private $underscoreNamingStrategy;
public function __construct(
UnderscoreNamingStrategy $underscoreNamingStrategy
) {
$this->underscoreNamingStrategy = $underscoreNamingStrategy;
}
function classToTableName($className)
{
return $this->underscoreNamingStrategy->classToTableName($className);
}
function propertyToColumnName($propertyName, $className = null)
{
return $this->classToTableName($className) . '_' .
$this->underscoreNamingStrategy->propertyToColumnName($propertyName, $className);
}
function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null)
{
return $this->classToTableName($className) . '_' .
$this->underscoreNamingStrategy->embeddedFieldToColumnName(
$propertyName,
$embeddedColumnName,
$className,
$embeddedClassName
);
}
function referenceColumnName()
{
return $this->underscoreNamingStrategy->referenceColumnName();
}
function joinColumnName($propertyName, string $className = null) // TODO: No in interface, but passed anyway
{
return $this->classToTableName($className) . '_' .
$this->underscoreNamingStrategy->joinColumnName($propertyName);
}
function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
{
return $this->underscoreNamingStrategy->joinTableName($sourceEntity, $targetEntity);
}
function joinKeyColumnName($entityName, $referencedColumnName = null)
{
return $this->underscoreNamingStrategy->joinKeyColumnName($entityName, $referencedColumnName);
}
}