3

I have this entry for Entity Route. I want to sort entitiy list trplist on another field, but by default the sorting is done on id.

What is configuration change I need to make?

oneToMany: trplist: targetEntity: TravelRoutePoints mappedBy: route cascade: ["persist", "remove"] joinColumn: name: id referencedColumnName: tr_id

1 Answer 1

11

I guess the dostrine OrderBy annotation is what you're looking for:

/**
 * @ManyToMany(targetEntity="Group")
 * @OrderBy({"name" = "ASC"})
 */
private $groups;

see docs: http://docs.doctrine-project.org/en/latest/reference/annotations-reference.html#orderby

So, your relation in yaml format should look like:

oneToMany:
    trplist:
        targetEntity: TravelRoutePoints
        mappedBy: route
        cascade: ["persist", "remove"] 
        joinColumn: 
            name: id 
            referencedColumnName: tr_id
        orderBy:
            anotherFieldName: DESC
1
  • I am using yml for configuration, whats the syntax for order by there?
    – Bads123
    Feb 8, 2014 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.