Ensure <cascade/> elements preceed <join-columns/>
When converting annotations based metadata to XML, the position of the <cascade/> elements resulted in XSD validation errors caused by the definitions of the association ComplexTypes: - https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd#L463 - https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd#L482 - https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd#L495 - https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd#L517 Since changing the XSD might result in validation problems in existing mappings, changing the XmlExporter seems a better approach. Note that the '<cache/>' element is not yet generated by the XmlExporter, but according to the XML Schema, it should precede the '<cascade/>' element.
This commit is contained in:
parent
69cad4079d
commit
85a16f9f28
@ -261,6 +261,39 @@ class XmlExporter extends AbstractExporter
|
|||||||
$associationMappingXml->addAttribute('orphan-removal', 'true');
|
$associationMappingXml->addAttribute('orphan-removal', 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cascade = array();
|
||||||
|
if ($associationMapping['isCascadeRemove']) {
|
||||||
|
$cascade[] = 'cascade-remove';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($associationMapping['isCascadePersist']) {
|
||||||
|
$cascade[] = 'cascade-persist';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($associationMapping['isCascadeRefresh']) {
|
||||||
|
$cascade[] = 'cascade-refresh';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($associationMapping['isCascadeMerge']) {
|
||||||
|
$cascade[] = 'cascade-merge';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($associationMapping['isCascadeDetach']) {
|
||||||
|
$cascade[] = 'cascade-detach';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($cascade) === 5) {
|
||||||
|
$cascade = array('cascade-all');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cascade) {
|
||||||
|
$cascadeXml = $associationMappingXml->addChild('cascade');
|
||||||
|
|
||||||
|
foreach ($cascade as $type) {
|
||||||
|
$cascadeXml->addChild($type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($associationMapping['joinTable']) && $associationMapping['joinTable']) {
|
if (isset($associationMapping['joinTable']) && $associationMapping['joinTable']) {
|
||||||
$joinTableXml = $associationMappingXml->addChild('join-table');
|
$joinTableXml = $associationMappingXml->addChild('join-table');
|
||||||
$joinTableXml->addAttribute('name', $associationMapping['joinTable']['name']);
|
$joinTableXml->addAttribute('name', $associationMapping['joinTable']['name']);
|
||||||
@ -330,39 +363,6 @@ class XmlExporter extends AbstractExporter
|
|||||||
$orderByFieldXml->addAttribute('direction', $direction);
|
$orderByFieldXml->addAttribute('direction', $direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$cascade = array();
|
|
||||||
|
|
||||||
if ($associationMapping['isCascadeRemove']) {
|
|
||||||
$cascade[] = 'cascade-remove';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($associationMapping['isCascadePersist']) {
|
|
||||||
$cascade[] = 'cascade-persist';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($associationMapping['isCascadeRefresh']) {
|
|
||||||
$cascade[] = 'cascade-refresh';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($associationMapping['isCascadeMerge']) {
|
|
||||||
$cascade[] = 'cascade-merge';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($associationMapping['isCascadeDetach']) {
|
|
||||||
$cascade[] = 'cascade-detach';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($cascade) === 5) {
|
|
||||||
$cascade = array('cascade-all');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($cascade) {
|
|
||||||
$cascadeXml = $associationMappingXml->addChild('cascade');
|
|
||||||
|
|
||||||
foreach ($cascade as $type) {
|
|
||||||
$cascadeXml->addChild($type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($metadata->lifecycleCallbacks) && count($metadata->lifecycleCallbacks)>0) {
|
if (isset($metadata->lifecycleCallbacks) && count($metadata->lifecycleCallbacks)>0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user