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

XML one-to-many order-by default direction isn't set #7141

Closed
Awkan opened this issue Mar 20, 2018 · 2 comments
Closed

XML one-to-many order-by default direction isn't set #7141

Awkan opened this issue Mar 20, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@Awkan
Copy link
Contributor

Awkan commented Mar 20, 2018

Context

I have a oneToMany relation between 2 entities. For example an Article which has many tags.

class Article
{
    private $id;
    private $name;
    private $tags;

    public function __construct()
    {
        $this->tags = new ArrayCollection();
    }
}

class Tag
{
    private $id;
    private $name;
}

My mapping is declared as XML.

Then, I want to get my tags ordered by name. For that, I have the following mapping in my Article:

<entity name="Article">
    <!-- ... -->
            <one-to-many field="tags" target-entity="Tag">
            <order-by>
                <order-by-field name="name"/>
            </order-by>
        </one-to-many>
</entity>

Problem

By default, this should sort my name field ASC (as mentionned in XSD file). However I have the exception Invalid order by orientation specified for Tag#name

Way of solution

For the moment, adding explicitly my direction attribute works fine but the default value isn't very default

<entity name="Article">
    <!-- ... -->
            <one-to-many field="tags" target-entity="Tag">
            <order-by>
                <order-by-field name="name" direction="ASC"/>
            </order-by>
        </one-to-many>
</entity>

I've investigate about it and it's appear that during the mapping reading (https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php#L375), the default direction isn't set. Should be set it by default to this line ?

@Ocramius
Copy link
Member

@Awkan setting the default direction (if not set) in the driver is likely the correct approach.

Awkan added a commit to Awkan/doctrine2 that referenced this issue Mar 20, 2018
Awkan added a commit to Awkan/doctrine2 that referenced this issue Mar 21, 2018
Awkan added a commit to Awkan/doctrine2 that referenced this issue Mar 22, 2018
Awkan added a commit to Awkan/doctrine2 that referenced this issue Mar 22, 2018
Majkl578 pushed a commit to Majkl578/doctrine-orm that referenced this issue Jun 29, 2018
@lcobucci lcobucci added the Bug label Nov 20, 2018
@lcobucci lcobucci added this to the 2.6.2 milestone Nov 20, 2018
@lcobucci
Copy link
Member

Fixed by #7146

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

No branches or pull requests

3 participants