New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NamingStrategy::joinTableName not being called #5655
Conversation
This problem exists for M2M without a tableName (because a NamingStrategy may take care of the table name) and XML Drivers Explanation: Although a joinTable MUST have an tableName eventually, it is actually valid to have it not declared IF a naming strategy would generate one (always true if not defined (null)). However this XML driver will will parse an omitted declaration as an empty string. The ClassMetadataInfo Class is expecting an unset value or it will break. ClassMetadataInfo will show a `Notice: Uninitialized string offset: 0` which makes sense if you look at (see)[https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L1521] ``` // with $mapping['joinTable']['name'] = ''; if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] === '`') { ``` More importantly the (default) naming strategy will now never be called and the resulting ClassMetadataInfo has no table name defined, which results in a 'Invalid table name specified' Exception (see)[https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L1703-L1705] ``` if ( ! isset($mapping['joinTable']['name'])) { $mapping['joinTable']['name'] = $this->namingStrategy->joinTableName($mapping['sourceEntity'], $mapping['targetEntity'], $mapping['fieldName']); } ``` Please tell me if this is something we can merge without further proof, I don't really understand how to add a test case for it (I have looked at the existing cases, but... pfft)
@basz please refer to https://github.com/doctrine/doctrine2/blob/788143dc0313c7522820ebf6057f73881e7190a3/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php You basically want to create a |
Otherwise Naming strategies will never be able to kick in for xml schemes |
A join table can be omitted |
Not if you want to specify other properties. I would argue that the doctrine-mapping.xsd is incorrect on the requirement of the name attribute since doctrine supported NamingStrategies... This should work IMHO
|
@basz changing the requirement could be done, but is it worth doing? |
Probably not. but if it is not accurate, why not? For example skipper will try to generate a join column name when omitted. When asked to stop doing they will probably say it a requirement by declaration.
|
This problem exists for M2M without a tableName (because a NamingStrategy may take care of the table name) and XML Drivers
Explanation:
Although a joinTable MUST have an tableName eventually, it is actually valid to have it not declared IF a naming strategy would generate one (always true if not defined (null)).
However this XML driver will will parse an omitted declaration as an empty string. The ClassMetadataInfo Class is expecting an unset value or it will break.
ClassMetadataInfo will show a
Notice: Uninitialized string offset: 0
which makes sense if you look atsee
More importantly the (default) naming strategy will now never be called and the resulting ClassMetadataInfo has no table name defined, which results in a 'Invalid table name specified' Exception
see
Please tell me if this is something we can merge without further proof, I don't really understand how to add a test case for it (I have looked at the existing cases, but... pfft)