Skip to content
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

Weird XML associations error #6444

Closed
szymach opened this issue May 15, 2017 · 4 comments
Closed

Weird XML associations error #6444

szymach opened this issue May 15, 2017 · 4 comments
Assignees

Comments

@szymach
Copy link

szymach commented May 15, 2017

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.

@szymach
Copy link
Author

szymach commented 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?

@Ocramius
Copy link
Member

@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)

@greg0ire
Copy link
Member

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

@szymach
Copy link
Author

szymach commented Jan 26, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants