Weird XML associations error #5535

Closed
opened 2026-01-22 15:10:21 +01:00 by admin · 4 comments
Owner

Originally created by @szymach on GitHub (May 15, 2017).

Originally assigned to: @szymach on GitHub.

I have an XML file as follows:

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
    <entity name="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableAccordionBlockTranslation"
            table="content_block_translatable_accordion_translation">
        <field name="locale" type="string" length="2" nullable="true"/>
        <one-to-many field="elements"
                     target-entity="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableAccordionElement"
                     mapped-by="accordionBlockTranslation" orphan-removal="true">
            <cascade>
                <cascade-persist/>
                <cascade-remove/>
            </cascade>
            <order-by>
                <order-by-field name="position" direction="ASC"/>
            </order-by>
        </one-to-many>
        <many-to-one field="block"
                     target-entity="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableAccordionBlock"
                     inversed-by="translations">
            <join-column name="block" referenced-column-name="id" on-delete="CASCADE"/>
        </many-to-one>
    </entity>
</doctrine-mapping>

which works fine, but when I switch the order of one-to-many and many-to-one relations in the file, I get an error:

Warning: DOMDocument::schemaValidateSource(): Element '{http://doctrine-project.org/schemas/orm/doctrine-mapping}one-to-many': This element is not expected. Expected is one of ( {http://doctrine-project.org/schemas/orm/doctrine-mapping}many-to-one, {http://doctrine-project.org/schemas/orm/doctrine-mapping}many-to-many, {http://doctrine-project.org/schemas/orm/doctrine-mapping}association-overrides, {http://doctrine-project.org/schemas/orm/doctrine-mapping}attribute-overrides, ##other{http://doctrine-project.org/schemas/orm/doctrine-mapping}* ). 

Here are my Doctrine-related packages:

doctrine/annotations                   v1.0    Docblock Annotations Parser
doctrine/cache                         v1.3.0  Caching library offering an object-oriented API for many cache backends
doctrine/collections                   v1.1    Collections Abstraction library
doctrine/common                        v2.4.0  Common Library for Doctrine projects
doctrine/data-fixtures                 v1.0.0  Data Fixtures for all Doctrine Object Managers
doctrine/dbal                          v2.4.0  Database Abstraction Layer
doctrine/doctrine-bundle               v1.5.0  Symfony DoctrineBundle
doctrine/doctrine-cache-bundle         1.0.0   Symfony2 Bundle for Doctrine Cache
doctrine/inflector                     v1.0    Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                  1.0.4   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                         v1.0    Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm       

Funny thing is, I have a file:

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                  http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableFilesBlockTranslation"
            table="content_block_translatable_files_translation">
        <field name="locale" type="string" length="2" nullable="true"/>
        <many-to-one field="block"
                     target-entity="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableFilesBlock"
                     inversed-by="translations">
            <join-columns>
                <join-column name="block" referenced-column-name="id" on-delete="CASCADE"/>
            </join-columns>
        </many-to-one>
        <one-to-many field="elements"
                     target-entity="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableFilesElement"
                     mapped-by="filesBlockTranslation" orphan-removal="true">
            <cascade>
                <cascade-persist/>
                <cascade-remove/>
            </cascade>
            <order-by>
                <order-by-field name="position" direction="ASC"/>
            </order-by>
        </one-to-many>
    </entity>
</doctrine-mapping>

and it works perfectly fine.

Originally created by @szymach on GitHub (May 15, 2017). Originally assigned to: @szymach on GitHub. I have an XML file as follows: ```xml <?xml version="1.0" encoding="UTF-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd"> <entity name="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableAccordionBlockTranslation" table="content_block_translatable_accordion_translation"> <field name="locale" type="string" length="2" nullable="true"/> <one-to-many field="elements" target-entity="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableAccordionElement" mapped-by="accordionBlockTranslation" orphan-removal="true"> <cascade> <cascade-persist/> <cascade-remove/> </cascade> <order-by> <order-by-field name="position" direction="ASC"/> </order-by> </one-to-many> <many-to-one field="block" target-entity="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableAccordionBlock" inversed-by="translations"> <join-column name="block" referenced-column-name="id" on-delete="CASCADE"/> </many-to-one> </entity> </doctrine-mapping> ``` which works fine, but when I switch the order of `one-to-many` and `many-to-one` relations in the file, I get an error: ``` Warning: DOMDocument::schemaValidateSource(): Element '{http://doctrine-project.org/schemas/orm/doctrine-mapping}one-to-many': This element is not expected. Expected is one of ( {http://doctrine-project.org/schemas/orm/doctrine-mapping}many-to-one, {http://doctrine-project.org/schemas/orm/doctrine-mapping}many-to-many, {http://doctrine-project.org/schemas/orm/doctrine-mapping}association-overrides, {http://doctrine-project.org/schemas/orm/doctrine-mapping}attribute-overrides, ##other{http://doctrine-project.org/schemas/orm/doctrine-mapping}* ). ``` Here are my Doctrine-related packages: ``` doctrine/annotations v1.0 Docblock Annotations Parser doctrine/cache v1.3.0 Caching library offering an object-oriented API for many cache backends doctrine/collections v1.1 Collections Abstraction library doctrine/common v2.4.0 Common Library for Doctrine projects doctrine/data-fixtures v1.0.0 Data Fixtures for all Doctrine Object Managers doctrine/dbal v2.4.0 Database Abstraction Layer doctrine/doctrine-bundle v1.5.0 Symfony DoctrineBundle doctrine/doctrine-cache-bundle 1.0.0 Symfony2 Bundle for Doctrine Cache doctrine/inflector v1.0 Common String Manipulations with regard to casing and singular/plural rules. doctrine/instantiator 1.0.4 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer v1.0 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers. doctrine/orm ``` Funny thing is, I have a file: ```xml <?xml version="1.0" encoding="UTF-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableFilesBlockTranslation" table="content_block_translatable_files_translation"> <field name="locale" type="string" length="2" nullable="true"/> <many-to-one field="block" target-entity="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableFilesBlock" inversed-by="translations"> <join-columns> <join-column name="block" referenced-column-name="id" on-delete="CASCADE"/> </join-columns> </many-to-one> <one-to-many field="elements" target-entity="FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableFilesElement" mapped-by="filesBlockTranslation" orphan-removal="true"> <cascade> <cascade-persist/> <cascade-remove/> </cascade> <order-by> <order-by-field name="position" direction="ASC"/> </order-by> </one-to-many> </entity> </doctrine-mapping> ``` and it works perfectly fine.
admin added the BugInvalid labels 2026-01-22 15:10:21 +01:00
admin closed this issue 2026-01-22 15:10:22 +01:00
Author
Owner

@szymach commented on GitHub (May 19, 2017):

Some of you more keenly eyed may have noticed the different xsi:schemaLocation values, but that is only due to my fiddling and trying to figure out what was wrong.

Basically what happened is that I have basically copied FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableFilesBlockTranslation mapping to FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableAccordionBlockTranslation and adjusted class/relation names and it broke for the latter, where the former have worked previously. I understand this may be due to schema enforcing order of nodes, but why does it sometimes work and sometimes not?

@szymach commented on GitHub (May 19, 2017): Some of you more keenly eyed may have noticed the different `xsi:schemaLocation` values, but that is only due to my fiddling and trying to figure out what was wrong. Basically what happened is that I have basically copied `FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableFilesBlockTranslation` mapping to `FSi\Bundle\ContentBlockBundle\Entity\TranslatableBlock\TranslatableAccordionBlockTranslation` and adjusted class/relation names and it broke for the latter, where the former have worked previously. I understand this may be due to schema enforcing order of nodes, but why does it sometimes work and sometimes not?
Author
Owner

@Ocramius commented on GitHub (May 20, 2017):

@szymach XSD validation is not enabled at all times: a full trace should show where the failure is happening, but the XML driver doesn't do validation on its own, if I recall correctly (it should, though)

@Ocramius commented on GitHub (May 20, 2017): @szymach XSD validation is not enabled at all times: a full trace should show where the failure is happening, but the XML driver doesn't do validation on its own, if I recall correctly (it should, though)
Author
Owner

@greg0ire commented on GitHub (Sep 25, 2017):

@Ocramius would something like #6728 be ok? Should I continue or is there something wrong with it?

@greg0ire commented on GitHub (Sep 25, 2017): @Ocramius would something like #6728 be ok? Should I continue or is there something wrong with it?
Author
Owner

@szymach commented on GitHub (Jan 26, 2018):

Yeah the was on our part, our library had a sneaky bug when it came to validating XMLs. Closing.

@szymach commented on GitHub (Jan 26, 2018): Yeah the was on our part, our library had a sneaky bug when it came to validating XMLs. Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5535