mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
NamingStrategy::referenceColumnName not used in OneToOne relation (Annotations) #5585
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @jennevdmeer on GitHub (Jun 22, 2017).
Some obligatory versions to start with quoted from the source files:
I tried implementing a custom naming strategy for increased auto naming flexibility and added CamelCase. This is currently loaded and works with the exception of:
In the case of a OneToOne using annotations (have not checked other methods),
referenceColumnName()is not referenced in the call chain all the way back to theJoinColumn::$referencedColumnNameclass default (id), resulting in the error:As it should be
Id(Workaround's at the end). Now starting with my: class CamelCaseNamingStrategy implements NamingStrategyIs here my manual trace to find out the origin of the lowercase 'id' starting at the point of my error message:
SchemaValidator.php#L208
So I dumped the
$joinColumn:And traced the
referencedColumnNameto ClassMetaDataInfo::_validateAndCompleteOneToOneMapping()However the passed in
$mappingargument already contains"referencedColumnName" => "id"so any of thereferencedColumnName = $this->namingStrategy->referenceColumnName()are ignored as they are all conditioned to only work when joinColumns or referencedColumnName == null.So continueing the callstack traversal:
ClassMetadataInfo.php
public function mapOneToOne(array $mapping) {AnnotationDriver.php
$metadata->mapOneToOne($mapping);$mapping['joinColumns'] = $joinColumns;$joinColumns[] = $this->joinColumnToArray($joinColumnAnnot);Where
$joinColumnAnnotis:Which brought me to JoinColumn.php
public $referencedColumnName = 'id';So that is where it stopped for me. Changing that to
Idsolves it, or just removing the default value seems to work as well. As im using composer (with symfony) I'd rather not modify vendor classes so for now my workaround is to use@ORM\JoinColumn(referencedColumnName="Id").I don't know if it was something I did, or it indeed is a bug. As I am just a humble php peasant with little doctrine knowledge this goes too deep down the well for me.
@Ocramius commented on GitHub (Jun 22, 2017):
@jennevdmeer I updated the link references - remember to not link
master, but absolute hashes or tags, becausemastermoves ;-)@Ocramius commented on GitHub (Jun 22, 2017):
@jennevdmeer you tried really hard to describe what is going on here, and indeed it's a long standing bug about the default value of
$referencedColumnName, which should be inferred rather than pre-assigned.Still, a test case would be much more efficient for starting a fix: see
af1ea1ae1d/tests/Doctrine/Tests/ORM/Functional/Ticketfor examplesThe test would just:
Eventually you can also configure the ORM with a fake naming strategy there (a mock, for example) to check that it is being called.
From that point on, it's all just implementation details about how to fix this properly.