Search code examples
symfonypropel

How to order related propel model in symfony2 form


I am using symfony2 form along with propel. I am having trouble on how to order the related entity from propel's model.

The abstracted code below, is taken from http://www.propelorm.org/cookbook/symfony2/mastering-symfony2-forms-with-propel.html, which show how to relate them together. I am wondering how do I order them.

$builder->add('author', 'model', array(
    'class' => 'Acme\LibraryBundle\Model\Author',
));

For Example, If in my author table there are columns name, age,.... How should make it to order by name.


Solution

  • $builder->add('author', 'model', array(
        'class' => 'Acme\LibraryBundle\Model\Author', 
        'query' => \Acme\LibraryBundle\Mode\AuthorQuery::create()->orderByName()
    ));