Search code examples
doctrine-ormdql

Doctrine 2 ORDER BY the field of a joinTable


I have an Entity defined like this:

Munkatars:
    id:
        id:
            type: integer
    fields:
        nev:
            type: text
        [...]
    manyToOne:
        vezeto:
            targetEntity: Munkatars
            inversedBy: alarendeltek
    oneToMany:
        alarendeltek:
            targetEntity: Munkatars
            mappedBy: vezeto
            fetch: EXTRA_LAZY

Is there a way to create a query that orders these Munkatars objects by their vezeto's nev field?

I've tried ORDER BY m.vezeto.nev, but that gave me an error, and the documentation didn't give much information on this.


Solution

  • you must use join like this example:

    createQuery("SELECT m.nev 
                 FROM  Entity\Munkatars as m 
                 LEFT JOIN m.vezeto as v
                 ORDER BY v.nev");